Merge pull request #2783 from atom/fix-devtools-extension

Fix `BrowserWindow.addDevToolsExtension` not working
This commit is contained in:
Cheng Zhao 2015-09-15 10:38:02 +08:00
commit dc59b4fa06
8 changed files with 26 additions and 7 deletions

View file

@ -7,6 +7,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "atom/common/atom_version.h"
#include "atom/common/chrome_version.h" #include "atom/common/chrome_version.h"
#include "atom/common/options_switches.h" #include "atom/common/options_switches.h"
#include "base/command_line.h" #include "base/command_line.h"
@ -14,6 +15,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "content/public/common/content_constants.h" #include "content/public/common/content_constants.h"
#include "content/public/common/pepper_plugin_info.h" #include "content/public/common/pepper_plugin_info.h"
#include "content/public/common/user_agent.h"
#include "ppapi/shared_impl/ppapi_permissions.h" #include "ppapi/shared_impl/ppapi_permissions.h"
namespace atom { namespace atom {
@ -72,6 +74,12 @@ std::string AtomContentClient::GetProduct() const {
return "Chrome/" CHROME_VERSION_STRING; 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( void AtomContentClient::AddAdditionalSchemes(
std::vector<std::string>* standard_schemes, std::vector<std::string>* standard_schemes,
std::vector<std::string>* savable_schemes) { std::vector<std::string>* savable_schemes) {

View file

@ -20,6 +20,7 @@ class AtomContentClient : public brightray::ContentClient {
protected: protected:
// content::ContentClient: // content::ContentClient:
std::string GetProduct() const override; std::string GetProduct() const override;
std::string GetUserAgent() const override;
void AddAdditionalSchemes( void AddAdditionalSchemes(
std::vector<std::string>* standard_schemes, std::vector<std::string>* standard_schemes,
std::vector<std::string>* savable_schemes) override; std::vector<std::string>* savable_schemes) override;

View file

@ -547,6 +547,10 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
web_contents()->GetController().LoadURLWithParams(params); web_contents()->GetController().LoadURLWithParams(params);
} }
GURL WebContents::GetURL() const {
return web_contents()->GetURL();
}
base::string16 WebContents::GetTitle() const { base::string16 WebContents::GetTitle() const {
return web_contents()->GetTitle(); return web_contents()->GetTitle();
} }
@ -815,6 +819,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
.SetMethod("getId", &WebContents::GetID) .SetMethod("getId", &WebContents::GetID)
.SetMethod("equal", &WebContents::Equal) .SetMethod("equal", &WebContents::Equal)
.SetMethod("_loadUrl", &WebContents::LoadURL) .SetMethod("_loadUrl", &WebContents::LoadURL)
.SetMethod("_getUrl", &WebContents::GetURL)
.SetMethod("getTitle", &WebContents::GetTitle) .SetMethod("getTitle", &WebContents::GetTitle)
.SetMethod("isLoading", &WebContents::IsLoading) .SetMethod("isLoading", &WebContents::IsLoading)
.SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse) .SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse)

View file

@ -55,6 +55,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
int GetID() const; int GetID() const;
bool Equal(const WebContents* web_contents) const; bool Equal(const WebContents* web_contents) const;
void LoadURL(const GURL& url, const mate::Dictionary& options); void LoadURL(const GURL& url, const mate::Dictionary& options);
GURL GetURL() const;
base::string16 GetTitle() const; base::string16 GetTitle() const;
bool IsLoading() const; bool IsLoading() const;
bool IsWaitingForResponse() const; bool IsWaitingForResponse() const;

View file

@ -183,21 +183,21 @@ void Window::OnDevToolsFocus() {
} }
void Window::OnDevToolsOpened() { void Window::OnDevToolsOpened() {
Emit("devtools-opened");
v8::Locker locker(isolate()); v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate()); v8::HandleScope handle_scope(isolate());
auto handle = WebContents::CreateFrom( auto handle = WebContents::CreateFrom(
isolate(), api_web_contents_->GetDevToolsWebContents()); isolate(), api_web_contents_->GetDevToolsWebContents());
devtools_web_contents_.Reset(isolate(), handle.ToV8()); devtools_web_contents_.Reset(isolate(), handle.ToV8());
Emit("devtools-opened");
} }
void Window::OnDevToolsClosed() { void Window::OnDevToolsClosed() {
Emit("devtools-closed");
v8::Locker locker(isolate()); v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate()); v8::HandleScope handle_scope(isolate());
devtools_web_contents_.Reset(); devtools_web_contents_.Reset();
Emit("devtools-closed");
} }
void Window::OnExecuteWindowsCommand(const std::string& command_name) { void Window::OnExecuteWindowsCommand(const std::string& command_name) {

View file

@ -16,6 +16,11 @@ class NavigationController
constructor: (@webContents) -> constructor: (@webContents) ->
@clearHistory() @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) => @webContents.on 'navigation-entry-commited', (event, url, inPage, replaceEntry) =>
if @inPageIndex > -1 and not inPage if @inPageIndex > -1 and not inPage
# Navigated to a new page, clear in-page mark. # Navigated to a new page, clear in-page mark.

View file

@ -44,10 +44,8 @@ wrapWebContents = (webContents) ->
# Make sure webContents.executeJavaScript would run the code only when the # Make sure webContents.executeJavaScript would run the code only when the
# web contents has been loaded. # web contents has been loaded.
webContents.loaded = false
webContents.once 'did-finish-load', -> @loaded = true
webContents.executeJavaScript = (code, hasUserGesture=false) -> webContents.executeJavaScript = (code, hasUserGesture=false) ->
if @loaded if @getUrl() and not @isLoading()
@_executeJavaScript code, hasUserGesture @_executeJavaScript code, hasUserGesture
else else
webContents.once 'did-finish-load', @_executeJavaScript.bind(this, code, hasUserGesture) webContents.once 'did-finish-load', @_executeJavaScript.bind(this, code, hasUserGesture)

View file

@ -32,6 +32,7 @@ getExtensionInfoFromPath = (srcDirectory) ->
startPage: page startPage: page
name: manifest.name name: manifest.name
srcDirectory: srcDirectory srcDirectory: srcDirectory
exposeExperimentalAPIs: true
extensionInfoMap[manifest.name] extensionInfoMap[manifest.name]
# The loaded extensions cache and its persistent path. # The loaded extensions cache and its persistent path.