mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Flushing things we don't need
This commit is contained in:
@@ -115,29 +115,6 @@ static NSAutoreleasePool* g_autopool = nil;
|
||||
[alert runModal];
|
||||
}
|
||||
|
||||
- (void)notifyConsoleMessage:(id)object {
|
||||
std::stringstream ss;
|
||||
ss << "Console messages will be written to " << g_handler->GetLogFile();
|
||||
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
|
||||
[self alert:@"Console Messages" withMessage:str];
|
||||
}
|
||||
|
||||
- (void)notifyDownloadComplete:(id)object {
|
||||
std::stringstream ss;
|
||||
ss << "File \"" << g_handler->GetLastDownloadFile() <<
|
||||
"\" downloaded successfully.";
|
||||
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
|
||||
[self alert:@"File Download" withMessage:str];
|
||||
}
|
||||
|
||||
- (void)notifyDownloadError:(id)object {
|
||||
std::stringstream ss;
|
||||
ss << "File \"" << g_handler->GetLastDownloadFile() <<
|
||||
"\" failed to download.";
|
||||
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
|
||||
[self alert:@"File Download" withMessage:str];
|
||||
}
|
||||
|
||||
- (void)windowDidBecomeKey:(NSNotification*)notification {
|
||||
if (g_handler.get() && g_handler->GetBrowserId()) {
|
||||
// Give focus to the browser window.
|
||||
|
||||
@@ -17,16 +17,6 @@
|
||||
#include "cefclient/client_renderer.h"
|
||||
|
||||
|
||||
// Custom menu command Ids.
|
||||
enum client_menu_ids {
|
||||
CLIENT_ID_SHOW_DEVTOOLS = MENU_ID_USER_FIRST,
|
||||
CLIENT_ID_TESTMENU_SUBMENU,
|
||||
CLIENT_ID_TESTMENU_CHECKITEM,
|
||||
CLIENT_ID_TESTMENU_RADIOITEM1,
|
||||
CLIENT_ID_TESTMENU_RADIOITEM2,
|
||||
CLIENT_ID_TESTMENU_RADIOITEM3,
|
||||
};
|
||||
|
||||
ClientHandler::ClientHandler()
|
||||
: m_MainHwnd(NULL),
|
||||
m_BrowserId(0),
|
||||
@@ -86,24 +76,13 @@ void ClientHandler::OnBeforeContextMenu(
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefContextMenuParams> params,
|
||||
CefRefPtr<CefMenuModel> model) {
|
||||
if ((params->GetTypeFlags() & (CM_TYPEFLAG_PAGE | CM_TYPEFLAG_FRAME)) != 0) {
|
||||
// Add a separator if the menu already has items.
|
||||
if (model->GetCount() > 0)
|
||||
model->AddSeparator();
|
||||
|
||||
// Add a "Show DevTools" item to all context menus.
|
||||
model->AddItem(CLIENT_ID_SHOW_DEVTOOLS, "&Show DevTools");
|
||||
model->AddItem(MENU_ID_USER_FIRST, "&Show DevTools");
|
||||
CefString devtools_url = browser->GetHost()->GetDevToolsURL(true);
|
||||
|
||||
CefString devtools_url = browser->GetHost()->GetDevToolsURL(true);
|
||||
if (devtools_url.empty() ||
|
||||
m_OpenDevToolsURLs.find(devtools_url) != m_OpenDevToolsURLs.end()) {
|
||||
// Disable the menu option if DevTools isn't enabled or if a window is
|
||||
// already open for the current URL.
|
||||
model->SetEnabled(CLIENT_ID_SHOW_DEVTOOLS, false);
|
||||
}
|
||||
|
||||
// Test context menu features.
|
||||
BuildTestMenu(model);
|
||||
// Disable the menu option if DevTools isn't enabled or if a window already open for the current URL.
|
||||
if (devtools_url.empty() || m_OpenDevToolsURLs.find(devtools_url) != m_OpenDevToolsURLs.end()) {
|
||||
model->SetEnabled(MENU_ID_USER_FIRST, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,12 +92,13 @@ bool ClientHandler::OnContextMenuCommand(
|
||||
CefRefPtr<CefContextMenuParams> params,
|
||||
int command_id,
|
||||
EventFlags event_flags) {
|
||||
switch (command_id) {
|
||||
case CLIENT_ID_SHOW_DEVTOOLS:
|
||||
ShowDevTools(browser);
|
||||
return true;
|
||||
default: // Allow default handling, if any.
|
||||
return ExecuteTestMenu(command_id);
|
||||
|
||||
if (command_id == MENU_ID_USER_FIRST) {
|
||||
ShowDevTools(browser);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,8 +107,6 @@ void ClientHandler::OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
||||
bool canGoBack,
|
||||
bool canGoForward) {
|
||||
REQUIRE_UI_THREAD();
|
||||
SetLoading(isLoading);
|
||||
SetNavState(canGoBack, canGoForward);
|
||||
}
|
||||
|
||||
bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||
@@ -146,8 +124,6 @@ void ClientHandler::OnBeforeDownload(
|
||||
const CefString& suggested_name,
|
||||
CefRefPtr<CefBeforeDownloadCallback> callback) {
|
||||
REQUIRE_UI_THREAD();
|
||||
// Continue the download and show the "Save As" dialog.
|
||||
callback->Continue(GetDownloadPath(suggested_name), true);
|
||||
}
|
||||
|
||||
void ClientHandler::OnDownloadUpdated(
|
||||
@@ -155,10 +131,6 @@ void ClientHandler::OnDownloadUpdated(
|
||||
CefRefPtr<CefDownloadItem> download_item,
|
||||
CefRefPtr<CefDownloadItemCallback> callback) {
|
||||
REQUIRE_UI_THREAD();
|
||||
if (download_item->IsComplete()) {
|
||||
SetLastDownloadFile(download_item->GetFullPath());
|
||||
SendNotification(NOTIFY_DOWNLOAD_COMPLETE);
|
||||
}
|
||||
}
|
||||
|
||||
void ClientHandler::OnRequestGeolocationPermission(
|
||||
@@ -166,8 +138,6 @@ void ClientHandler::OnRequestGeolocationPermission(
|
||||
const CefString& requesting_url,
|
||||
int request_id,
|
||||
CefRefPtr<CefGeolocationCallback> callback) {
|
||||
// Allow geolocation access from all websites.
|
||||
callback->Continue(true);
|
||||
}
|
||||
|
||||
bool ClientHandler::OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||
@@ -211,13 +181,12 @@ bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) {
|
||||
void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if (m_BrowserId == browser->GetIdentifier()) {
|
||||
// Free the browser pointer so that the browser can be destroyed
|
||||
m_Browser = NULL;
|
||||
} else if (browser->IsPopup()) {
|
||||
if (m_BrowserId == browser->GetIdentifier()) {
|
||||
m_Browser = NULL; // Free the browser pointer so that the browser can be destroyed
|
||||
}
|
||||
else if (browser->IsPopup()) {
|
||||
// Remove the record for DevTools popup windows.
|
||||
std::set<std::string>::iterator it =
|
||||
m_OpenDevToolsURLs.find(browser->GetMainFrame()->GetURL());
|
||||
std::set<std::string>::iterator it = m_OpenDevToolsURLs.find(browser->GetMainFrame()->GetURL());
|
||||
if (it != m_OpenDevToolsURLs.end())
|
||||
m_OpenDevToolsURLs.erase(it);
|
||||
}
|
||||
@@ -226,22 +195,12 @@ void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
|
||||
void ClientHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if (m_BrowserId == browser->GetIdentifier() && frame->IsMain()) {
|
||||
// We've just started loading a page
|
||||
SetLoading(true);
|
||||
}
|
||||
}
|
||||
|
||||
void ClientHandler::OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if (m_BrowserId == browser->GetIdentifier() && frame->IsMain()) {
|
||||
// We've just finished loading a page
|
||||
SetLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
|
||||
@@ -251,24 +210,18 @@ void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& failedUrl) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Don't display an error for downloaded files.
|
||||
if (errorCode == ERR_ABORTED)
|
||||
if (errorCode == ERR_ABORTED) // Don't display an error for downloaded files.
|
||||
return;
|
||||
else if (errorCode == ERR_UNKNOWN_URL_SCHEME) { // Don't display an error for external protocols that we allow the OS to handle. See OnProtocolExecution().
|
||||
return;
|
||||
|
||||
// Don't display an error for external protocols that we allow the OS to
|
||||
// handle. See OnProtocolExecution().
|
||||
if (errorCode == ERR_UNKNOWN_URL_SCHEME) {
|
||||
std::string urlStr = frame->GetURL();
|
||||
if (urlStr.find("spotify:") == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
// Display a load error message.
|
||||
std::stringstream ss;
|
||||
ss << "<html><body><h2>Failed to load URL " << std::string(failedUrl) <<
|
||||
" with error " << std::string(errorText) << " (" << errorCode <<
|
||||
").</h2></body></html>";
|
||||
frame->LoadString(ss.str(), failedUrl);
|
||||
else {
|
||||
std::stringstream ss;
|
||||
ss << "<html><body><h2>Failed to load URL " << std::string(failedUrl) <<
|
||||
" with error " << std::string(errorText) << " (" << errorCode <<
|
||||
").</h2></body></html>";
|
||||
frame->LoadString(ss.str(), failedUrl);
|
||||
}
|
||||
}
|
||||
|
||||
void ClientHandler::OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
|
||||
@@ -341,14 +294,11 @@ void ClientHandler::ShowDevTools(CefRefPtr<CefBrowser> browser) {
|
||||
std::string devtools_url = browser->GetHost()->GetDevToolsURL(true);
|
||||
if (!devtools_url.empty()) {
|
||||
if (m_bExternalDevTools) {
|
||||
// Open DevTools in an external browser window.
|
||||
LaunchExternalBrowser(devtools_url);
|
||||
} else if (m_OpenDevToolsURLs.find(devtools_url) ==
|
||||
m_OpenDevToolsURLs.end()) {
|
||||
// Open DevTools in a popup window.
|
||||
m_OpenDevToolsURLs.insert(devtools_url);
|
||||
browser->GetMainFrame()->ExecuteJavaScript(
|
||||
"window.open('" + devtools_url + "');", "about:blank", 0);
|
||||
LaunchExternalBrowser(devtools_url); // Open DevTools in an external browser window.
|
||||
}
|
||||
else if (m_OpenDevToolsURLs.find(devtools_url) == m_OpenDevToolsURLs.end()) {
|
||||
m_OpenDevToolsURLs.insert(devtools_url); // Open DevTools in a popup window.
|
||||
browser->GetMainFrame()->ExecuteJavaScript("window.open('" + devtools_url + "');", "about:blank", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -384,40 +334,3 @@ void ClientHandler::CreateProcessMessageDelegates(
|
||||
// static
|
||||
void ClientHandler::CreateRequestDelegates(RequestDelegateSet& delegates) {
|
||||
}
|
||||
|
||||
void ClientHandler::BuildTestMenu(CefRefPtr<CefMenuModel> model) {
|
||||
if (model->GetCount() > 0)
|
||||
model->AddSeparator();
|
||||
|
||||
// Build the sub menu.
|
||||
CefRefPtr<CefMenuModel> submenu =
|
||||
model->AddSubMenu(CLIENT_ID_TESTMENU_SUBMENU, "Context Menu Test");
|
||||
submenu->AddCheckItem(CLIENT_ID_TESTMENU_CHECKITEM, "Check Item");
|
||||
submenu->AddRadioItem(CLIENT_ID_TESTMENU_RADIOITEM1, "Radio Item 1", 0);
|
||||
submenu->AddRadioItem(CLIENT_ID_TESTMENU_RADIOITEM2, "Radio Item 2", 0);
|
||||
submenu->AddRadioItem(CLIENT_ID_TESTMENU_RADIOITEM3, "Radio Item 3", 0);
|
||||
|
||||
// Check the check item.
|
||||
if (m_TestMenuState.check_item)
|
||||
submenu->SetChecked(CLIENT_ID_TESTMENU_CHECKITEM, true);
|
||||
|
||||
// Check the selected radio item.
|
||||
submenu->SetChecked(
|
||||
CLIENT_ID_TESTMENU_RADIOITEM1 + m_TestMenuState.radio_item, true);
|
||||
}
|
||||
|
||||
bool ClientHandler::ExecuteTestMenu(int command_id) {
|
||||
if (command_id == CLIENT_ID_TESTMENU_CHECKITEM) {
|
||||
// Toggle the check item.
|
||||
m_TestMenuState.check_item ^= 1;
|
||||
return true;
|
||||
} else if (command_id >= CLIENT_ID_TESTMENU_RADIOITEM1 &&
|
||||
command_id <= CLIENT_ID_TESTMENU_RADIOITEM3) {
|
||||
// Store the selected radio item.
|
||||
m_TestMenuState.radio_item = (command_id - CLIENT_ID_TESTMENU_RADIOITEM1);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow default handling to proceed.
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ class ClientHandler : public CefClient,
|
||||
NOTIFY_DOWNLOAD_COMPLETE,
|
||||
NOTIFY_DOWNLOAD_ERROR,
|
||||
};
|
||||
void SendNotification(NotificationType type);
|
||||
|
||||
void CloseMainWindow();
|
||||
|
||||
void ShowDevTools(CefRefPtr<CefBrowser> browser);
|
||||
@@ -211,8 +211,6 @@ class ClientHandler : public CefClient,
|
||||
static void LaunchExternalBrowser(const std::string& url);
|
||||
|
||||
protected:
|
||||
void SetLoading(bool isLoading);
|
||||
void SetNavState(bool canGoBack, bool canGoForward);
|
||||
|
||||
// Create all of ProcessMessageDelegate objects.
|
||||
static void CreateProcessMessageDelegates(
|
||||
|
||||
@@ -17,64 +17,20 @@ void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& url) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if (m_BrowserId == browser->GetIdentifier() && frame->IsMain()) {
|
||||
// Set the edit window text
|
||||
NSTextField* textField = (NSTextField*)m_EditHwnd;
|
||||
std::string urlStr(url);
|
||||
NSString* str = [NSString stringWithUTF8String:urlStr.c_str()];
|
||||
[textField setStringValue:str];
|
||||
}
|
||||
}
|
||||
|
||||
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) {
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set the frame window title bar
|
||||
NSView* view = (NSView*)browser->GetHost()->GetWindowHandle();
|
||||
NSWindow* window = [view window];
|
||||
std::string titleStr(title);
|
||||
NSString* str = [NSString stringWithUTF8String:titleStr.c_str()];
|
||||
[window setTitle:str];
|
||||
}
|
||||
|
||||
void ClientHandler::SendNotification(NotificationType type) {
|
||||
SEL sel = nil;
|
||||
switch(type) {
|
||||
case NOTIFY_CONSOLE_MESSAGE:
|
||||
sel = @selector(notifyConsoleMessage:);
|
||||
break;
|
||||
case NOTIFY_DOWNLOAD_COMPLETE:
|
||||
sel = @selector(notifyDownloadComplete:);
|
||||
break;
|
||||
case NOTIFY_DOWNLOAD_ERROR:
|
||||
sel = @selector(notifyDownloadError:);
|
||||
break;
|
||||
}
|
||||
|
||||
if (sel == nil)
|
||||
return;
|
||||
|
||||
void ClientHandler::CloseMainWindow() {
|
||||
NSWindow* window = nil;
|
||||
#ifndef PROCESS_HELPER_APP
|
||||
if (g_handler.get()) window = (NSWindow *)g_handler->GetMainHwnd();
|
||||
#endif
|
||||
|
||||
NSObject* delegate = [window delegate];
|
||||
[delegate performSelectorOnMainThread:sel withObject:nil waitUntilDone:NO];
|
||||
}
|
||||
|
||||
void ClientHandler::SetLoading(bool isLoading) {
|
||||
// TODO(port): Change button status.
|
||||
}
|
||||
|
||||
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) {
|
||||
// TODO(port): Change button status.
|
||||
}
|
||||
|
||||
void ClientHandler::CloseMainWindow() {
|
||||
// TODO(port): Close window
|
||||
|
||||
[window performSelectorOnMainThread:@selector(close) withObject:nil waitUntilDone:NO];
|
||||
}
|
||||
|
||||
std::string ClientHandler::GetDownloadPath(const std::string& file_name) {
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "cefclient/client_renderer.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
Reference in New Issue
Block a user