From a5dc911a057f897c1ae915db27a69ed3e6789682 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 14 Sep 2015 22:49:22 +0800 Subject: [PATCH 1/6] Correctly set user agent for devtools --- atom/app/atom_content_client.cc | 8 ++++++++ atom/app/atom_content_client.h | 1 + 2 files changed, 9 insertions(+) diff --git a/atom/app/atom_content_client.cc b/atom/app/atom_content_client.cc index 1ba1f20315..e760c01453 100644 --- a/atom/app/atom_content_client.cc +++ b/atom/app/atom_content_client.cc @@ -7,6 +7,7 @@ #include #include +#include "atom/common/atom_version.h" #include "atom/common/chrome_version.h" #include "atom/common/options_switches.h" #include "base/command_line.h" @@ -14,6 +15,7 @@ #include "base/strings/string_util.h" #include "content/public/common/content_constants.h" #include "content/public/common/pepper_plugin_info.h" +#include "content/public/common/user_agent.h" #include "ppapi/shared_impl/ppapi_permissions.h" namespace atom { @@ -72,6 +74,12 @@ std::string AtomContentClient::GetProduct() const { return "Chrome/" CHROME_VERSION_STRING; } +std::string AtomContentClient::GetUserAgent() const { + return content::BuildUserAgentFromProduct( + "Chrome/" CHROME_VERSION_STRING " " + ATOM_PRODUCT_NAME "/" ATOM_VERSION_STRING); +} + void AtomContentClient::AddAdditionalSchemes( std::vector* standard_schemes, std::vector* savable_schemes) { diff --git a/atom/app/atom_content_client.h b/atom/app/atom_content_client.h index 279ec7179f..a6b2f73e7f 100644 --- a/atom/app/atom_content_client.h +++ b/atom/app/atom_content_client.h @@ -20,6 +20,7 @@ class AtomContentClient : public brightray::ContentClient { protected: // content::ContentClient: std::string GetProduct() const override; + std::string GetUserAgent() const override; void AddAdditionalSchemes( std::vector* standard_schemes, std::vector* savable_schemes) override; From f140f35910b2c3d1270f3678e8785eb7d3b33aaf Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 14 Sep 2015 22:47:20 +0800 Subject: [PATCH 2/6] Expose experiment APIs --- atom/browser/lib/chrome-extension.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/atom/browser/lib/chrome-extension.coffee b/atom/browser/lib/chrome-extension.coffee index df0d717cd9..15f7bfd54c 100644 --- a/atom/browser/lib/chrome-extension.coffee +++ b/atom/browser/lib/chrome-extension.coffee @@ -32,6 +32,7 @@ getExtensionInfoFromPath = (srcDirectory) -> startPage: page name: manifest.name srcDirectory: srcDirectory + exposeExperimentalAPIs: true extensionInfoMap[manifest.name] # The loaded extensions cache and its persistent path. From 3bf73bc45518c127cc43418c98104be89e773e64 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 15 Sep 2015 09:17:45 +0800 Subject: [PATCH 3/6] Expose native implementation of WebContent::GetURL --- atom/browser/api/atom_api_web_contents.cc | 5 +++++ atom/browser/api/atom_api_web_contents.h | 1 + 2 files changed, 6 insertions(+) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 7c37f17e10..a24200e5a8 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -547,6 +547,10 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) { web_contents()->GetController().LoadURLWithParams(params); } +GURL WebContents::GetURL() const { + return web_contents()->GetURL(); +} + base::string16 WebContents::GetTitle() const { return web_contents()->GetTitle(); } @@ -815,6 +819,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( .SetMethod("getId", &WebContents::GetID) .SetMethod("equal", &WebContents::Equal) .SetMethod("_loadUrl", &WebContents::LoadURL) + .SetMethod("_getUrl", &WebContents::GetURL) .SetMethod("getTitle", &WebContents::GetTitle) .SetMethod("isLoading", &WebContents::IsLoading) .SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 3c6bde9c24..0001d3e8ef 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -55,6 +55,7 @@ class WebContents : public mate::TrackableObject, int GetID() const; bool Equal(const WebContents* web_contents) const; void LoadURL(const GURL& url, const mate::Dictionary& options); + GURL GetURL() const; base::string16 GetTitle() const; bool IsLoading() const; bool IsWaitingForResponse() const; From 238d4add9925c43614a04eb9d2632808f54ff0ed Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 15 Sep 2015 09:18:22 +0800 Subject: [PATCH 4/6] devtools-opened should be emitted after devtools is opened --- atom/browser/api/atom_api_window.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 7403a7ecbb..ede6bcd71e 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -183,21 +183,21 @@ void Window::OnDevToolsFocus() { } void Window::OnDevToolsOpened() { - Emit("devtools-opened"); - v8::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); auto handle = WebContents::CreateFrom( isolate(), api_web_contents_->GetDevToolsWebContents()); devtools_web_contents_.Reset(isolate(), handle.ToV8()); + + Emit("devtools-opened"); } void Window::OnDevToolsClosed() { - Emit("devtools-closed"); - v8::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); devtools_web_contents_.Reset(); + + Emit("devtools-closed"); } void Window::OnExecuteWindowsCommand(const std::string& command_name) { From e656d8428cc463aecb3477717257d1c2494ec694 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 15 Sep 2015 09:20:56 +0800 Subject: [PATCH 5/6] Make getUrl work for devToolsWebContents --- atom/browser/api/lib/navigation-controller.coffee | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/atom/browser/api/lib/navigation-controller.coffee b/atom/browser/api/lib/navigation-controller.coffee index a985931f47..f78d92c341 100644 --- a/atom/browser/api/lib/navigation-controller.coffee +++ b/atom/browser/api/lib/navigation-controller.coffee @@ -16,6 +16,11 @@ class NavigationController constructor: (@webContents) -> @clearHistory() + # webContents may have already navigated to a page. + if @webContents._getUrl() + @currentIndex++ + @history.push @webContents._getUrl() + @webContents.on 'navigation-entry-commited', (event, url, inPage, replaceEntry) => if @inPageIndex > -1 and not inPage # Navigated to a new page, clear in-page mark. From 8a8b11cf10f0c107f91915e407e021f95a8f3c38 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 15 Sep 2015 09:21:15 +0800 Subject: [PATCH 6/6] Do not use did-finish-load to detect whether WebContents is ready The WebContents JS object can be created way later after the C++ object gets created. --- atom/browser/api/lib/web-contents.coffee | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/atom/browser/api/lib/web-contents.coffee b/atom/browser/api/lib/web-contents.coffee index 1bb82dec1a..3a2abfb515 100644 --- a/atom/browser/api/lib/web-contents.coffee +++ b/atom/browser/api/lib/web-contents.coffee @@ -44,10 +44,8 @@ wrapWebContents = (webContents) -> # Make sure webContents.executeJavaScript would run the code only when the # web contents has been loaded. - webContents.loaded = false - webContents.once 'did-finish-load', -> @loaded = true webContents.executeJavaScript = (code, hasUserGesture=false) -> - if @loaded + if @getUrl() and not @isLoading() @_executeJavaScript code, hasUserGesture else webContents.once 'did-finish-load', @_executeJavaScript.bind(this, code, hasUserGesture)