diff --git a/atom/app/atom_content_client.cc b/atom/app/atom_content_client.cc index 1ba1f2031564..e760c01453d4 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 279ec7179f49..a6b2f73e7faa 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; diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 7c37f17e10d9..a24200e5a87d 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 3c6bde9c24aa..0001d3e8ef75 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; diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 7403a7ecbb77..ede6bcd71e6b 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) { diff --git a/atom/browser/api/lib/navigation-controller.coffee b/atom/browser/api/lib/navigation-controller.coffee index a985931f4716..f78d92c341d6 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. diff --git a/atom/browser/api/lib/web-contents.coffee b/atom/browser/api/lib/web-contents.coffee index 1bb82dec1a66..3a2abfb5155f 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) diff --git a/atom/browser/lib/chrome-extension.coffee b/atom/browser/lib/chrome-extension.coffee index df0d717cd9dd..15f7bfd54c56 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.