Discard is_guest_, use type_ instead

This commit is contained in:
Cheng Zhao 2015-06-24 22:23:38 +08:00
parent 2bfa9da82e
commit 19ca011735
5 changed files with 24 additions and 30 deletions

View file

@ -149,8 +149,7 @@ WebContents::WebContents(brightray::InspectableWebContents* web_contents)
} }
WebContents::WebContents(content::WebContents* web_contents) WebContents::WebContents(content::WebContents* web_contents)
: CommonWebContentsDelegate(false), : content::WebContentsObserver(web_contents),
content::WebContentsObserver(web_contents),
guest_opaque_(true), guest_opaque_(true),
guest_host_(nullptr), guest_host_(nullptr),
auto_size_enabled_(false), auto_size_enabled_(false),
@ -161,8 +160,7 @@ WebContents::WebContents(content::WebContents* web_contents)
} }
WebContents::WebContents(const mate::Dictionary& options) WebContents::WebContents(const mate::Dictionary& options)
: CommonWebContentsDelegate(true), : guest_opaque_(true),
guest_opaque_(true),
guest_host_(nullptr), guest_host_(nullptr),
auto_size_enabled_(false), auto_size_enabled_(false),
is_full_page_plugin_(false), is_full_page_plugin_(false),
@ -235,6 +233,10 @@ content::WebContents* WebContents::OpenURLFromTab(
return CommonWebContentsDelegate::OpenURLFromTab(source, params); return CommonWebContentsDelegate::OpenURLFromTab(source, params);
} }
bool WebContents::IsPopupOrPanel(const content::WebContents* source) const {
return type_ == BROWSER_WINDOW;
}
void WebContents::HandleKeyboardEvent( void WebContents::HandleKeyboardEvent(
content::WebContents* source, content::WebContents* source,
const content::NativeWebKeyboardEvent& event) { const content::NativeWebKeyboardEvent& event) {
@ -412,7 +414,7 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) {
} }
void WebContents::RenderViewReady() { void WebContents::RenderViewReady() {
if (!is_guest()) if (type_ != WEB_VIEW)
return; return;
// We don't want to accidentally set the opacity of an interstitial page. // We don't want to accidentally set the opacity of an interstitial page.
@ -466,7 +468,7 @@ void WebContents::WillAttach(content::WebContents* embedder_web_contents,
} }
void WebContents::Destroy() { void WebContents::Destroy() {
if (is_guest() && managed_web_contents()) { if (type_ == WEB_VIEW && managed_web_contents()) {
// When force destroying the "destroyed" event is not emitted. // When force destroying the "destroyed" event is not emitted.
WebContentsDestroyed(); WebContentsDestroyed();
@ -561,10 +563,11 @@ void WebContents::ExecuteJavaScript(const base::string16& code) {
} }
void WebContents::OpenDevTools(mate::Arguments* args) { void WebContents::OpenDevTools(mate::Arguments* args) {
if (!inspectable_web_contents()) if (type_ == REMOTE)
return; return;
bool detach = false; bool detach = false;
if (is_guest()) { if (type_ == WEB_VIEW) {
detach = true; detach = true;
} else if (args && args->Length() == 1) { } else if (args && args->Length() == 1) {
mate::Dictionary options; mate::Dictionary options;
@ -575,13 +578,14 @@ void WebContents::OpenDevTools(mate::Arguments* args) {
} }
void WebContents::CloseDevTools() { void WebContents::CloseDevTools() {
if (!inspectable_web_contents()) if (type_ == REMOTE)
return; return;
inspectable_web_contents()->CloseDevTools(); inspectable_web_contents()->CloseDevTools();
} }
bool WebContents::IsDevToolsOpened() { bool WebContents::IsDevToolsOpened() {
if (!inspectable_web_contents()) if (type_ == REMOTE)
return false; return false;
return inspectable_web_contents()->IsDevToolsViewShowing(); return inspectable_web_contents()->IsDevToolsViewShowing();
} }
@ -594,8 +598,9 @@ void WebContents::ToggleDevTools() {
} }
void WebContents::InspectElement(int x, int y) { void WebContents::InspectElement(int x, int y) {
if (!inspectable_web_contents()) if (type_ == REMOTE)
return; return;
OpenDevTools(nullptr); OpenDevTools(nullptr);
scoped_refptr<content::DevToolsAgentHost> agent( scoped_refptr<content::DevToolsAgentHost> agent(
content::DevToolsAgentHost::GetOrCreateFor(web_contents())); content::DevToolsAgentHost::GetOrCreateFor(web_contents()));
@ -603,8 +608,9 @@ void WebContents::InspectElement(int x, int y) {
} }
void WebContents::InspectServiceWorker() { void WebContents::InspectServiceWorker() {
if (!inspectable_web_contents()) if (type_ == REMOTE)
return; return;
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) { for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
if (agent_host->GetType() == if (agent_host->GetType() ==
content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { content::DevToolsAgentHost::TYPE_SERVICE_WORKER) {
@ -790,7 +796,7 @@ void WebContents::SetAllowTransparency(bool allow) {
} }
bool WebContents::IsGuest() const { bool WebContents::IsGuest() const {
return is_guest(); return type_ == WEB_VIEW;
} }
mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(

View file

@ -164,6 +164,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
content::WebContents* OpenURLFromTab( content::WebContents* OpenURLFromTab(
content::WebContents* source, content::WebContents* source,
const content::OpenURLParams& params) override; const content::OpenURLParams& params) override;
bool IsPopupOrPanel(const content::WebContents* source) const override;
void HandleKeyboardEvent( void HandleKeyboardEvent(
content::WebContents* source, content::WebContents* source,
const content::NativeWebKeyboardEvent& event) override; const content::NativeWebKeyboardEvent& event) override;

View file

@ -107,9 +107,8 @@ void AppendToFile(const base::FilePath& path,
} // namespace } // namespace
CommonWebContentsDelegate::CommonWebContentsDelegate(bool is_guest) CommonWebContentsDelegate::CommonWebContentsDelegate()
: is_guest_(is_guest), : owner_window_(nullptr),
owner_window_(nullptr),
html_fullscreen_(false), html_fullscreen_(false),
native_fullscreen_(false) { native_fullscreen_(false) {
} }
@ -180,11 +179,6 @@ bool CommonWebContentsDelegate::CanOverscrollContent() const {
return false; return false;
} }
bool CommonWebContentsDelegate::IsPopupOrPanel(
const content::WebContents* source) const {
return !is_guest_;
}
content::JavaScriptDialogManager* content::JavaScriptDialogManager*
CommonWebContentsDelegate::GetJavaScriptDialogManager( CommonWebContentsDelegate::GetJavaScriptDialogManager(
content::WebContents* source) { content::WebContents* source) {

View file

@ -23,7 +23,7 @@ class CommonWebContentsDelegate
: public brightray::DefaultWebContentsDelegate, : public brightray::DefaultWebContentsDelegate,
public brightray::InspectableWebContentsDelegate { public brightray::InspectableWebContentsDelegate {
public: public:
explicit CommonWebContentsDelegate(bool is_guest); CommonWebContentsDelegate();
virtual ~CommonWebContentsDelegate(); virtual ~CommonWebContentsDelegate();
// Create a InspectableWebContents object and takes onwership of // Create a InspectableWebContents object and takes onwership of
@ -44,8 +44,6 @@ class CommonWebContentsDelegate
return web_contents_.get(); return web_contents_.get();
} }
bool is_guest() const { return is_guest_; }
protected: protected:
// content::WebContentsDelegate: // content::WebContentsDelegate:
content::WebContents* OpenURLFromTab( content::WebContents* OpenURLFromTab(
@ -55,7 +53,6 @@ class CommonWebContentsDelegate
bool user_gesture, bool user_gesture,
bool last_unlocked_by_target) override; bool last_unlocked_by_target) override;
bool CanOverscrollContent() const override; bool CanOverscrollContent() const override;
bool IsPopupOrPanel(const content::WebContents* source) const override;
content::JavaScriptDialogManager* GetJavaScriptDialogManager( content::JavaScriptDialogManager* GetJavaScriptDialogManager(
content::WebContents* source) override; content::WebContents* source) override;
content::ColorChooser* OpenColorChooser( content::ColorChooser* OpenColorChooser(
@ -92,9 +89,6 @@ class CommonWebContentsDelegate
// Set fullscreen mode triggered by html api. // Set fullscreen mode triggered by html api.
void SetHtmlApiFullscreen(bool enter_fullscreen); void SetHtmlApiFullscreen(bool enter_fullscreen);
// Whether this is guest WebContents or NativeWindow.
const bool is_guest_;
// The window that this WebContents belongs to. // The window that this WebContents belongs to.
NativeWindow* owner_window_; NativeWindow* owner_window_;

View file

@ -85,8 +85,7 @@ std::string RemoveWhitespace(const std::string& str) {
NativeWindow::NativeWindow(content::WebContents* web_contents, NativeWindow::NativeWindow(content::WebContents* web_contents,
const mate::Dictionary& options) const mate::Dictionary& options)
: CommonWebContentsDelegate(false), : content::WebContentsObserver(web_contents),
content::WebContentsObserver(web_contents),
has_frame_(true), has_frame_(true),
transparent_(false), transparent_(false),
enable_larger_than_screen_(false), enable_larger_than_screen_(false),