Commit 8fdd9a89 authored by jeremya@chromium.org's avatar jeremya@chromium.org

Refactor ShellWindow to separate platform-specific code.



Review URL: https://chromiumcodereview.appspot.com/10825240

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152063 0039d316-1c4b-4281-b951-d872f2087c98
parent 999801a5
...@@ -104,7 +104,7 @@ bool AppWindowCreateFunction::RunImpl() { ...@@ -104,7 +104,7 @@ bool AppWindowCreateFunction::RunImpl() {
} }
ShellWindow* shell_window = ShellWindow* shell_window =
ShellWindow::Create(profile(), GetExtension(), url, create_params); ShellWindow::Create(profile(), GetExtension(), url, create_params);
shell_window->Show(); shell_window->GetBaseWindow()->Show();
content::WebContents* created_contents = shell_window->web_contents(); content::WebContents* created_contents = shell_window->web_contents();
int view_id = created_contents->GetRenderViewHost()->GetRoutingID(); int view_id = created_contents->GetRenderViewHost()->GetRoutingID();
...@@ -114,22 +114,22 @@ bool AppWindowCreateFunction::RunImpl() { ...@@ -114,22 +114,22 @@ bool AppWindowCreateFunction::RunImpl() {
} }
bool AppWindowFocusFunction::RunWithWindow(ShellWindow* window) { bool AppWindowFocusFunction::RunWithWindow(ShellWindow* window) {
window->Activate(); window->GetBaseWindow()->Activate();
return true; return true;
} }
bool AppWindowMaximizeFunction::RunWithWindow(ShellWindow* window) { bool AppWindowMaximizeFunction::RunWithWindow(ShellWindow* window) {
window->Maximize(); window->GetBaseWindow()->Maximize();
return true; return true;
} }
bool AppWindowMinimizeFunction::RunWithWindow(ShellWindow* window) { bool AppWindowMinimizeFunction::RunWithWindow(ShellWindow* window) {
window->Minimize(); window->GetBaseWindow()->Minimize();
return true; return true;
} }
bool AppWindowRestoreFunction::RunWithWindow(ShellWindow* window) { bool AppWindowRestoreFunction::RunWithWindow(ShellWindow* window) {
window->Restore(); window->GetBaseWindow()->Restore();
return true; return true;
} }
......
...@@ -116,7 +116,7 @@ void PlatformAppBrowserTest::CloseShellWindow(ShellWindow* window) { ...@@ -116,7 +116,7 @@ void PlatformAppBrowserTest::CloseShellWindow(ShellWindow* window) {
content::WindowedNotificationObserver destroyed_observer( content::WindowedNotificationObserver destroyed_observer(
content::NOTIFICATION_WEB_CONTENTS_DESTROYED, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
window->Close(); window->GetBaseWindow()->Close();
destroyed_observer.Wait(); destroyed_observer.Wait();
} }
......
...@@ -64,7 +64,7 @@ ShellWindow* ShellWindowRegistry::GetShellWindowForNativeWindow( ...@@ -64,7 +64,7 @@ ShellWindow* ShellWindowRegistry::GetShellWindowForNativeWindow(
gfx::NativeWindow window) const { gfx::NativeWindow window) const {
for (ShellWindowSet::const_iterator i = shell_windows_.begin(); for (ShellWindowSet::const_iterator i = shell_windows_.begin();
i != shell_windows_.end(); ++i) { i != shell_windows_.end(); ++i) {
if ((*i)->GetNativeWindow() == window) if ((*i)->GetBaseWindow()->GetNativeWindow() == window)
return *i; return *i;
} }
......
...@@ -653,7 +653,7 @@ void ChromeLauncherController::Observe( ...@@ -653,7 +653,7 @@ void ChromeLauncherController::Observe(
} }
void ChromeLauncherController::OnShellWindowAdded(ShellWindow* shell_window) { void ChromeLauncherController::OnShellWindowAdded(ShellWindow* shell_window) {
aura::Window* window = shell_window->GetNativeWindow(); aura::Window* window = shell_window->GetBaseWindow()->GetNativeWindow();
ash::LauncherItemStatus status = ash::wm::IsActiveWindow(window) ? ash::LauncherItemStatus status = ash::wm::IsActiveWindow(window) ?
ash::STATUS_ACTIVE : ash::STATUS_RUNNING; ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
window->AddObserver(this); window->AddObserver(this);
...@@ -713,7 +713,8 @@ void ChromeLauncherController::OnWindowRemovingFromRootWindow( ...@@ -713,7 +713,8 @@ void ChromeLauncherController::OnWindowRemovingFromRootWindow(
// We can't count on getting called before or after the ShellWindowRegistry. // We can't count on getting called before or after the ShellWindowRegistry.
if (remaining_windows.size() > 1 || if (remaining_windows.size() > 1 ||
(remaining_windows.size() == 1 && (remaining_windows.size() == 1 &&
(*remaining_windows.begin())->GetNativeWindow() != window)) { (*remaining_windows.begin())->GetBaseWindow()->GetNativeWindow() !=
window)) {
return; return;
} }
......
...@@ -10,10 +10,11 @@ ...@@ -10,10 +10,11 @@
#include "base/memory/scoped_nsobject.h" #include "base/memory/scoped_nsobject.h"
#include "chrome/browser/ui/cocoa/constrained_window_mac.h" #include "chrome/browser/ui/cocoa/constrained_window_mac.h"
#include "chrome/browser/ui/extensions/native_shell_window.h"
#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/common/extensions/draggable_region.h" #include "chrome/common/extensions/draggable_region.h"
#include "ui/gfx/rect.h"
#import "third_party/GTM/AppKit/GTMWindowSheetController.h" #import "third_party/GTM/AppKit/GTMWindowSheetController.h"
#include "ui/gfx/rect.h"
class Profile; class Profile;
class ShellWindowCocoa; class ShellWindowCocoa;
...@@ -35,12 +36,10 @@ class ShellWindowCocoa; ...@@ -35,12 +36,10 @@ class ShellWindowCocoa;
@end @end
// Cocoa bridge to ShellWindow. // Cocoa bridge to ShellWindow.
class ShellWindowCocoa : public ShellWindow { class ShellWindowCocoa : public NativeShellWindow {
public: public:
ShellWindowCocoa(Profile* profile, ShellWindowCocoa(ShellWindow* shell_window,
const extensions::Extension* extension, const ShellWindow::CreateParams& params);
const GURL& url,
const CreateParams& params);
// BaseWindow implementation. // BaseWindow implementation.
virtual bool IsActive() const OVERRIDE; virtual bool IsActive() const OVERRIDE;
...@@ -72,23 +71,31 @@ class ShellWindowCocoa : public ShellWindow { ...@@ -72,23 +71,31 @@ class ShellWindowCocoa : public ShellWindow {
void WindowDidResignKey(); void WindowDidResignKey();
protected: protected:
// ShellWindow implementation. // NativeShellWindow implementation.
virtual void SetFullscreen(bool fullscreen) OVERRIDE; virtual void SetFullscreen(bool fullscreen) OVERRIDE;
virtual bool IsFullscreenOrPending() const OVERRIDE; virtual bool IsFullscreenOrPending() const OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;
virtual void UpdateDraggableRegions(
const std::vector<extensions::DraggableRegion>& regions) OVERRIDE;
private: private:
virtual ~ShellWindowCocoa(); virtual ~ShellWindowCocoa();
// ShellWindow implementation.
virtual void UpdateDraggableRegions(
const std::vector<extensions::DraggableRegion>& regions) OVERRIDE;
NSWindow* window() const; NSWindow* window() const;
content::WebContents* web_contents() const {
return shell_window_->web_contents();
}
const extensions::Extension* extension() const {
return shell_window_->extension();
}
void InstallView(); void InstallView();
void UninstallView(); void UninstallView();
void InstallDraggableRegionViews(); void InstallDraggableRegionViews();
ShellWindow* shell_window_; // weak - ShellWindow owns NativeShellWindow.
bool has_frame_; bool has_frame_;
bool is_fullscreen_; bool is_fullscreen_;
......
...@@ -121,11 +121,9 @@ ...@@ -121,11 +121,9 @@
- (void)setMouseDownCanMoveWindow:(BOOL)can_move; - (void)setMouseDownCanMoveWindow:(BOOL)can_move;
@end @end
ShellWindowCocoa::ShellWindowCocoa(Profile* profile, ShellWindowCocoa::ShellWindowCocoa(ShellWindow* shell_window,
const extensions::Extension* extension,
const GURL& url,
const ShellWindow::CreateParams& params) const ShellWindow::CreateParams& params)
: ShellWindow(profile, extension, url), : shell_window_(shell_window),
has_frame_(params.frame == ShellWindow::CreateParams::FRAME_CHROME), has_frame_(params.frame == ShellWindow::CreateParams::FRAME_CHROME),
attention_request_id_(0) { attention_request_id_(0) {
// Flip coordinates based on the primary screen. // Flip coordinates based on the primary screen.
...@@ -141,7 +139,7 @@ ShellWindowCocoa::ShellWindowCocoa(Profile* profile, ...@@ -141,7 +139,7 @@ ShellWindowCocoa::ShellWindowCocoa(Profile* profile,
styleMask:style_mask styleMask:style_mask
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:NO]); defer:NO]);
[window setTitle:base::SysUTF8ToNSString(extension->name())]; [window setTitle:base::SysUTF8ToNSString(extension()->name())];
gfx::Size min_size = params.minimum_size; gfx::Size min_size = params.minimum_size;
if (min_size.width() || min_size.height()) { if (min_size.width() || min_size.height()) {
[window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())]; [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())];
...@@ -353,6 +351,10 @@ void ShellWindowCocoa::SetBounds(const gfx::Rect& bounds) { ...@@ -353,6 +351,10 @@ void ShellWindowCocoa::SetBounds(const gfx::Rect& bounds) {
[window() setFrame:cocoa_bounds display:YES]; [window() setFrame:cocoa_bounds display:YES];
} }
void ShellWindowCocoa::UpdateWindowTitle() {
// TODO(jeremya): implement.
}
void ShellWindowCocoa::UpdateDraggableRegions( void ShellWindowCocoa::UpdateDraggableRegions(
const std::vector<extensions::DraggableRegion>& regions) { const std::vector<extensions::DraggableRegion>& regions) {
// Draggable region is not supported for non-frameless window. // Draggable region is not supported for non-frameless window.
...@@ -412,7 +414,7 @@ bool ShellWindowCocoa::IsAlwaysOnTop() const { ...@@ -412,7 +414,7 @@ bool ShellWindowCocoa::IsAlwaysOnTop() const {
void ShellWindowCocoa::WindowWillClose() { void ShellWindowCocoa::WindowWillClose() {
[window_controller_ setShellWindow:NULL]; [window_controller_ setShellWindow:NULL];
OnNativeClose(); shell_window_->OnNativeClose();
} }
void ShellWindowCocoa::WindowDidBecomeKey() { void ShellWindowCocoa::WindowDidBecomeKey() {
...@@ -444,9 +446,7 @@ NSWindow* ShellWindowCocoa::window() const { ...@@ -444,9 +446,7 @@ NSWindow* ShellWindowCocoa::window() const {
} }
// static // static
ShellWindow* ShellWindow::CreateImpl(Profile* profile, NativeShellWindow* NativeShellWindow::Create(
const extensions::Extension* extension, ShellWindow* shell_window, const ShellWindow::CreateParams& params) {
const GURL& url, return new ShellWindowCocoa(shell_window, params);
const ShellWindow::CreateParams& params) {
return new ShellWindowCocoa(profile, extension, url, params);
} }
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_EXTENSIONS_NATIVE_SHELL_WINDOW_H_
#define CHROME_BROWSER_UI_EXTENSIONS_NATIVE_SHELL_WINDOW_H_
#include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/browser/ui/base_window.h"
// This is an interface to a native implementation of a shell window, used for
// new-style packaged apps. Shell windows contain a web contents, but no tabs
// or URL bar.
class NativeShellWindow : public BaseWindow {
public:
// Used by ShellWindow to instantiate the platform-specific ShellWindow code.
static NativeShellWindow* Create(ShellWindow* window,
const ShellWindow::CreateParams& params);
// Called when the title of the window changes.
virtual void UpdateWindowTitle() = 0;
// Called when the draggable regions are changed.
virtual void UpdateDraggableRegions(
const std::vector<extensions::DraggableRegion>& regions) {}
virtual void SetFullscreen(bool fullscreen) = 0;
virtual bool IsFullscreenOrPending() const = 0;
virtual ~NativeShellWindow() {}
};
#endif // CHROME_BROWSER_UI_EXTENSIONS_NATIVE_SHELL_WINDOW_H_
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/native_shell_window.h"
#include "chrome/browser/ui/intents/web_intent_picker_controller.h" #include "chrome/browser/ui/intents/web_intent_picker_controller.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/view_type_utils.h" #include "chrome/browser/view_type_utils.h"
...@@ -70,26 +71,25 @@ ShellWindow* ShellWindow::Create(Profile* profile, ...@@ -70,26 +71,25 @@ ShellWindow* ShellWindow::Create(Profile* profile,
const GURL& url, const GURL& url,
const ShellWindow::CreateParams& params) { const ShellWindow::CreateParams& params) {
// This object will delete itself when the window is closed. // This object will delete itself when the window is closed.
ShellWindow* window = ShellWindow* window = new ShellWindow(profile, extension);
ShellWindow::CreateImpl(profile, extension, url, params); window->Init(url, params);
extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window);
return window; return window;
} }
ShellWindow::ShellWindow(Profile* profile, ShellWindow::ShellWindow(Profile* profile,
const extensions::Extension* extension, const extensions::Extension* extension)
const GURL& url)
: profile_(profile), : profile_(profile),
extension_(extension), extension_(extension),
web_contents_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST( ALLOW_THIS_IN_INITIALIZER_LIST(
extension_function_dispatcher_(profile, this)) { extension_function_dispatcher_(profile, this)) {
// TODO(jeremya) this should all be done in an Init() method, not in the }
// constructor. During this code, WebContents will be calling
// WebContentsDelegate methods, but at this point the vftables for the void ShellWindow::Init(const GURL& url,
// subclass are not yet in place, since it's still halfway through its const ShellWindow::CreateParams& params) {
// constructor. As a result, overridden virtual methods won't be called.
web_contents_ = WebContents::Create( web_contents_ = WebContents::Create(
profile, SiteInstance::CreateForURL(profile, url), MSG_ROUTING_NONE, profile(), SiteInstance::CreateForURL(profile(), url), MSG_ROUTING_NONE,
NULL); NULL);
contents_.reset(new TabContents(web_contents_)); contents_.reset(new TabContents(web_contents_));
content::WebContentsObserver::Observe(web_contents_); content::WebContentsObserver::Observe(web_contents_);
...@@ -99,6 +99,8 @@ ShellWindow::ShellWindow(Profile* profile, ...@@ -99,6 +99,8 @@ ShellWindow::ShellWindow(Profile* profile,
browser_handles_all_top_level_requests = true; browser_handles_all_top_level_requests = true;
web_contents_->GetRenderViewHost()->SyncRendererPrefs(); web_contents_->GetRenderViewHost()->SyncRendererPrefs();
native_window_.reset(NativeShellWindow::Create(this, params));
// Block the created RVH from loading anything until the background page // Block the created RVH from loading anything until the background page
// has had a chance to do any initialization it wants. // has had a chance to do any initialization it wants.
SuspendRenderViewHost(web_contents_->GetRenderViewHost()); SuspendRenderViewHost(web_contents_->GetRenderViewHost());
...@@ -144,10 +146,6 @@ ShellWindow::~ShellWindow() { ...@@ -144,10 +146,6 @@ ShellWindow::~ShellWindow() {
browser::EndKeepAlive(); browser::EndKeepAlive();
} }
bool ShellWindow::IsFullscreenOrPending() const {
return false;
}
void ShellWindow::RequestMediaAccessPermission( void ShellWindow::RequestMediaAccessPermission(
content::WebContents* web_contents, content::WebContents* web_contents,
const content::MediaStreamRequest* request, const content::MediaStreamRequest* request,
...@@ -239,6 +237,10 @@ void ShellWindow::OnNativeClose() { ...@@ -239,6 +237,10 @@ void ShellWindow::OnNativeClose() {
delete this; delete this;
} }
BaseWindow* ShellWindow::GetBaseWindow() {
return native_window_.get();
}
string16 ShellWindow::GetTitle() const { string16 ShellWindow::GetTitle() const {
// WebContents::GetTitle() will return the page's URL if there's no <title> // WebContents::GetTitle() will return the page's URL if there's no <title>
// specified. However, we'd prefer to show the name of the extension in that // specified. However, we'd prefer to show the name of the extension in that
...@@ -260,8 +262,14 @@ bool ShellWindow::OnMessageReceived(const IPC::Message& message) { ...@@ -260,8 +262,14 @@ bool ShellWindow::OnMessageReceived(const IPC::Message& message) {
return handled; return handled;
} }
void ShellWindow::UpdateDraggableRegions(
const std::vector<extensions::DraggableRegion>& regions) {
native_window_->UpdateDraggableRegions(regions);
}
void ShellWindow::CloseContents(WebContents* contents) { void ShellWindow::CloseContents(WebContents* contents) {
Close(); DCHECK(contents == web_contents_);
native_window_->Close();
} }
bool ShellWindow::ShouldSuppressDialogs() { bool ShellWindow::ShouldSuppressDialogs() {
...@@ -293,26 +301,26 @@ bool ShellWindow::IsPopupOrPanel(const WebContents* source) const { ...@@ -293,26 +301,26 @@ bool ShellWindow::IsPopupOrPanel(const WebContents* source) const {
void ShellWindow::MoveContents(WebContents* source, const gfx::Rect& pos) { void ShellWindow::MoveContents(WebContents* source, const gfx::Rect& pos) {
DCHECK(source == web_contents_); DCHECK(source == web_contents_);
SetBounds(pos); native_window_->SetBounds(pos);
} }
void ShellWindow::NavigationStateChanged( void ShellWindow::NavigationStateChanged(
const content::WebContents* source, unsigned changed_flags) { const content::WebContents* source, unsigned changed_flags) {
DCHECK(source == web_contents_); DCHECK(source == web_contents_);
if (changed_flags & content::INVALIDATE_TYPE_TITLE) if (changed_flags & content::INVALIDATE_TYPE_TITLE)
UpdateWindowTitle(); native_window_->UpdateWindowTitle();
} }
void ShellWindow::ToggleFullscreenModeForTab(content::WebContents* source, void ShellWindow::ToggleFullscreenModeForTab(content::WebContents* source,
bool enter_fullscreen) { bool enter_fullscreen) {
DCHECK(source == web_contents_); DCHECK(source == web_contents_);
SetFullscreen(enter_fullscreen); native_window_->SetFullscreen(enter_fullscreen);
} }
bool ShellWindow::IsFullscreenForTabOrPending( bool ShellWindow::IsFullscreenForTabOrPending(
const content::WebContents* source) const { const content::WebContents* source) const {
DCHECK(source == web_contents_); DCHECK(source == web_contents_);
return IsFullscreenOrPending(); return native_window_->IsFullscreenOrPending();
} }
void ShellWindow::Observe(int type, void ShellWindow::Observe(int type,
...@@ -334,11 +342,11 @@ void ShellWindow::Observe(int type, ...@@ -334,11 +342,11 @@ void ShellWindow::Observe(int type,
content::Details<extensions::UnloadedExtensionInfo>( content::Details<extensions::UnloadedExtensionInfo>(
details)->extension; details)->extension;
if (extension_ == unloaded_extension) if (extension_ == unloaded_extension)
Close(); native_window_->Close();
break; break;
} }
case content::NOTIFICATION_APP_TERMINATING: case content::NOTIFICATION_APP_TERMINATING:
Close(); native_window_->Close();
break; break;
default: default:
NOTREACHED() << "Received unexpected notification"; NOTREACHED() << "Received unexpected notification";
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
class GURL; class GURL;
class Profile; class Profile;
class TabContents; class TabContents;
class NativeShellWindow;
namespace content { namespace content {
class WebContents; class WebContents;
...@@ -37,8 +38,7 @@ struct DraggableRegion; ...@@ -37,8 +38,7 @@ struct DraggableRegion;
class ShellWindow : public content::NotificationObserver, class ShellWindow : public content::NotificationObserver,
public content::WebContentsDelegate, public content::WebContentsDelegate,
public content::WebContentsObserver, public content::WebContentsObserver,
public ExtensionFunctionDispatcher::Delegate, public ExtensionFunctionDispatcher::Delegate {
public BaseWindow {
public: public:
struct CreateParams { struct CreateParams {
enum Frame { enum Frame {
...@@ -65,40 +65,33 @@ class ShellWindow : public content::NotificationObserver, ...@@ -65,40 +65,33 @@ class ShellWindow : public content::NotificationObserver,
const extensions::Extension* extension() const { return extension_; } const extensions::Extension* extension() const { return extension_; }
const TabContents* tab_contents() const { return contents_.get(); } const TabContents* tab_contents() const { return contents_.get(); }
content::WebContents* web_contents() const { return web_contents_; } content::WebContents* web_contents() const { return web_contents_; }
Profile* profile() const { return profile_; }
protected: BaseWindow* GetBaseWindow();
ShellWindow(Profile* profile, gfx::NativeWindow GetNativeWindow() {
const extensions::Extension* extension, return GetBaseWindow()->GetNativeWindow();
const GURL& url); }
virtual ~ShellWindow();
// Called when the title of the window changes. // NativeShellWindows should call this to determine what the window's title
virtual void UpdateWindowTitle() {} // is on startup and from within UpdateWindowTitle().
// Sub-classes should call this to determine what the window's title is on
// startup and from within UpdateWindowTitle().
virtual string16 GetTitle() const; virtual string16 GetTitle() const;
virtual void SetFullscreen(bool fullscreen) {}
virtual bool IsFullscreenOrPending() const;
// Called when the draggable regions are changed.
virtual void UpdateDraggableRegions(
const std::vector<extensions::DraggableRegion>& regions) {}
// Call to notify ShellRegistry and delete the window. Subclasses should // Call to notify ShellRegistry and delete the window. Subclasses should
// invoke this method instead of using "delete this". // invoke this method instead of using "delete this".
void OnNativeClose(); void OnNativeClose();
protected:
ShellWindow(Profile* profile,
const extensions::Extension* extension);
virtual ~ShellWindow();
private: private:
// PlatformAppBrowserTest needs access to web_contents() // PlatformAppBrowserTest needs access to web_contents()
friend class extensions::PlatformAppBrowserTest; friend class extensions::PlatformAppBrowserTest;
// Instantiates a platform-specific ShellWindow subclass (one implementation // Instantiates a platform-specific ShellWindow subclass (one implementation
// per platform). Public users of ShellWindow should use ShellWindow::Create. // per platform). Public users of ShellWindow should use ShellWindow::Create.
static ShellWindow* CreateImpl(Profile* profile, void Init(const GURL& url, const CreateParams& params);
const extensions::Extension* extension,
const GURL& url,
const CreateParams& params);
// content::WebContentsObserver implementation. // content::WebContentsObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
...@@ -151,6 +144,9 @@ class ShellWindow : public content::NotificationObserver, ...@@ -151,6 +144,9 @@ class ShellWindow : public content::NotificationObserver,
void AddMessageToDevToolsConsole(content::ConsoleMessageLevel level, void AddMessageToDevToolsConsole(content::ConsoleMessageLevel level,
const std::string& message); const std::string& message);
virtual void UpdateDraggableRegions(
const std::vector<extensions::DraggableRegion>& regions);
Profile* profile_; // weak pointer - owned by ProfileManager. Profile* profile_; // weak pointer - owned by ProfileManager.
// weak pointer - owned by ExtensionService. // weak pointer - owned by ExtensionService.
const extensions::Extension* extension_; const extensions::Extension* extension_;
...@@ -162,6 +158,8 @@ class ShellWindow : public content::NotificationObserver, ...@@ -162,6 +158,8 @@ class ShellWindow : public content::NotificationObserver,
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
ExtensionFunctionDispatcher extension_function_dispatcher_; ExtensionFunctionDispatcher extension_function_dispatcher_;
scoped_ptr<NativeShellWindow> native_window_;
DISALLOW_COPY_AND_ASSIGN(ShellWindow); DISALLOW_COPY_AND_ASSIGN(ShellWindow);
}; };
......
...@@ -13,11 +13,9 @@ ...@@ -13,11 +13,9 @@
#include "ui/base/x/active_window_watcher_x.h" #include "ui/base/x/active_window_watcher_x.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
ShellWindowGtk::ShellWindowGtk(Profile* profile, ShellWindowGtk::ShellWindowGtk(ShellWindow* shell_window,
const extensions::Extension* extension,
const GURL& url,
const ShellWindow::CreateParams& params) const ShellWindow::CreateParams& params)
: ShellWindow(profile, extension, url), : shell_window_(shell_window),
state_(GDK_WINDOW_STATE_WITHDRAWN), state_(GDK_WINDOW_STATE_WITHDRAWN),
is_active_(!ui::ActiveWindowWatcherX::WMSupportsActivation()), is_active_(!ui::ActiveWindowWatcherX::WMSupportsActivation()),
content_thinks_its_fullscreen_(false) { content_thinks_its_fullscreen_(false) {
...@@ -59,7 +57,7 @@ ShellWindowGtk::ShellWindowGtk(Profile* profile, ...@@ -59,7 +57,7 @@ ShellWindowGtk::ShellWindowGtk(Profile* profile,
} }
// TODO(mihaip): Mirror contents of <title> tag in window title // TODO(mihaip): Mirror contents of <title> tag in window title
gtk_window_set_title(window_, extension->name().c_str()); gtk_window_set_title(window_, extension()->name().c_str());
g_signal_connect(window_, "delete-event", g_signal_connect(window_, "delete-event",
G_CALLBACK(OnMainWindowDeleteEventThunk), this); G_CALLBACK(OnMainWindowDeleteEventThunk), this);
...@@ -121,7 +119,7 @@ void ShellWindowGtk::Close() { ...@@ -121,7 +119,7 @@ void ShellWindowGtk::Close() {
// OnNativeClose does a delete this so no other members should // OnNativeClose does a delete this so no other members should
// be accessed after. gtk_widget_destroy is safe (and must // be accessed after. gtk_widget_destroy is safe (and must
// be last). // be last).
OnNativeClose(); shell_window_->OnNativeClose();
gtk_widget_destroy(window); gtk_widget_destroy(window);
} }
...@@ -220,10 +218,12 @@ bool ShellWindowGtk::IsFullscreenOrPending() const { ...@@ -220,10 +218,12 @@ bool ShellWindowGtk::IsFullscreenOrPending() const {
return content_thinks_its_fullscreen_; return content_thinks_its_fullscreen_;
} }
void ShellWindowGtk::UpdateWindowTitle() {
// TODO(jeremya): implement.
}
// static // static
ShellWindow* ShellWindow::CreateImpl(Profile* profile, NativeShellWindow* NativeShellWindow::Create(
const extensions::Extension* extension, ShellWindow* shell_window, const ShellWindow::CreateParams& params) {
const GURL& url, return new ShellWindowGtk(shell_window, params);
const ShellWindow::CreateParams& params) {
return new ShellWindowGtk(profile, extension, url, params);
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "chrome/browser/ui/extensions/native_shell_window.h"
#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h"
#include "ui/base/gtk/gtk_signal.h" #include "ui/base/gtk/gtk_signal.h"
...@@ -19,14 +20,12 @@ namespace extensions { ...@@ -19,14 +20,12 @@ namespace extensions {
class Extension; class Extension;
} }
class ShellWindowGtk : public ShellWindow, class ShellWindowGtk : public NativeShellWindow,
public ExtensionViewGtk::Container, public ExtensionViewGtk::Container,
public ui::ActiveWindowWatcherXObserver { public ui::ActiveWindowWatcherXObserver {
public: public:
ShellWindowGtk(Profile* profile, ShellWindowGtk(ShellWindow* shell_window,
const extensions::Extension* extension, const ShellWindow::CreateParams& params);
const GURL& url,
const CreateParams& params);
// BaseWindow implementation. // BaseWindow implementation.
virtual bool IsActive() const OVERRIDE; virtual bool IsActive() const OVERRIDE;
...@@ -52,9 +51,17 @@ class ShellWindowGtk : public ShellWindow, ...@@ -52,9 +51,17 @@ class ShellWindowGtk : public ShellWindow,
virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE; virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE;
private: private:
// ShellWindow implementation. // NativeShellWindow implementation.
virtual void SetFullscreen(bool fullscreen) OVERRIDE; virtual void SetFullscreen(bool fullscreen) OVERRIDE;
virtual bool IsFullscreenOrPending() const OVERRIDE; virtual bool IsFullscreenOrPending() const OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;
content::WebContents* web_contents() const {
return shell_window_->web_contents();
}
const extensions::Extension* extension() const {
return shell_window_->extension();
}
virtual ~ShellWindowGtk(); virtual ~ShellWindowGtk();
...@@ -65,6 +72,8 @@ class ShellWindowGtk : public ShellWindow, ...@@ -65,6 +72,8 @@ class ShellWindowGtk : public ShellWindow,
CHROMEGTK_CALLBACK_1(ShellWindowGtk, gboolean, OnWindowState, CHROMEGTK_CALLBACK_1(ShellWindowGtk, gboolean, OnWindowState,
GdkEventWindowState*); GdkEventWindowState*);
ShellWindow* shell_window_; // weak - ShellWindow owns NativeShellWindow.
GtkWindow* window_; GtkWindow* window_;
GdkWindowState state_; GdkWindowState state_;
......
...@@ -302,11 +302,9 @@ void ShellWindowFrameView::ButtonPressed(views::Button* sender, ...@@ -302,11 +302,9 @@ void ShellWindowFrameView::ButtonPressed(views::Button* sender,
frame_->Close(); frame_->Close();
} }
ShellWindowViews::ShellWindowViews(Profile* profile, ShellWindowViews::ShellWindowViews(ShellWindow* shell_window,
const extensions::Extension* extension,
const GURL& url,
const ShellWindow::CreateParams& win_params) const ShellWindow::CreateParams& win_params)
: ShellWindow(profile, extension, url), : shell_window_(shell_window),
web_view_(NULL), web_view_(NULL),
is_fullscreen_(false), is_fullscreen_(false),
frameless_(win_params.frame == ShellWindow::CreateParams::FRAME_NONE) { frameless_(win_params.frame == ShellWindow::CreateParams::FRAME_NONE) {
...@@ -323,10 +321,10 @@ ShellWindowViews::ShellWindowViews(Profile* profile, ...@@ -323,10 +321,10 @@ ShellWindowViews::ShellWindowViews(Profile* profile,
window_->SetBounds(window_bounds); window_->SetBounds(window_bounds);
#if defined(OS_WIN) && !defined(USE_AURA) #if defined(OS_WIN) && !defined(USE_AURA)
std::string app_name = web_app::GenerateApplicationNameFromExtensionId( std::string app_name = web_app::GenerateApplicationNameFromExtensionId(
extension->id()); extension()->id());
ui::win::SetAppIdForWindow( ui::win::SetAppIdForWindow(
ShellIntegration::GetAppModelIdForProfile(UTF8ToWide(app_name), ShellIntegration::GetAppModelIdForProfile(
profile->GetPath()), UTF8ToWide(app_name), shell_window_->profile()->GetPath()),
GetWidget()->GetTopLevelWidget()->GetNativeWindow()); GetWidget()->GetTopLevelWidget()->GetNativeWindow());
#endif #endif
OnViewWasResized(); OnViewWasResized();
...@@ -455,7 +453,7 @@ bool ShellWindowViews::IsAlwaysOnTop() const { ...@@ -455,7 +453,7 @@ bool ShellWindowViews::IsAlwaysOnTop() const {
} }
void ShellWindowViews::DeleteDelegate() { void ShellWindowViews::DeleteDelegate() {
OnNativeClose(); shell_window_->OnNativeClose();
} }
bool ShellWindowViews::CanResize() const { bool ShellWindowViews::CanResize() const {
...@@ -478,7 +476,7 @@ views::NonClientFrameView* ShellWindowViews::CreateNonClientFrameView( ...@@ -478,7 +476,7 @@ views::NonClientFrameView* ShellWindowViews::CreateNonClientFrameView(
} }
string16 ShellWindowViews::GetWindowTitle() const { string16 ShellWindowViews::GetWindowTitle() const {
return GetTitle(); return shell_window_->GetTitle();
} }
views::Widget* ShellWindowViews::GetWidget() { views::Widget* ShellWindowViews::GetWidget() {
...@@ -536,7 +534,8 @@ void ShellWindowViews::OnViewWasResized() { ...@@ -536,7 +534,8 @@ void ShellWindowViews::OnViewWasResized() {
SkRegion::kUnion_Op); SkRegion::kUnion_Op);
} }
} }
web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn); if (web_contents()->GetRenderViewHost()->GetView())
web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn);
#endif #endif
} }
...@@ -580,9 +579,7 @@ void ShellWindowViews::UpdateDraggableRegions( ...@@ -580,9 +579,7 @@ void ShellWindowViews::UpdateDraggableRegions(
} }
// static // static
ShellWindow* ShellWindow::CreateImpl(Profile* profile, NativeShellWindow* NativeShellWindow::Create(
const extensions::Extension* extension, ShellWindow* shell_window, const ShellWindow::CreateParams& params) {
const GURL& url, return new ShellWindowViews(shell_window, params);
const ShellWindow::CreateParams& params) {
return new ShellWindowViews(profile, extension, url, params);
} }
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_SHELL_WINDOW_VIEWS_H_ #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_SHELL_WINDOW_VIEWS_H_
#define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_SHELL_WINDOW_VIEWS_H_ #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_SHELL_WINDOW_VIEWS_H_
#include "chrome/browser/ui/base_window.h"
#include "chrome/browser/ui/extensions/native_shell_window.h"
#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/extensions/shell_window.h"
#include "third_party/skia/include/core/SkRegion.h" #include "third_party/skia/include/core/SkRegion.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
...@@ -12,6 +14,10 @@ ...@@ -12,6 +14,10 @@
class Profile; class Profile;
namespace content {
class WebContents;
}
namespace extensions { namespace extensions {
class Extension; class Extension;
struct DraggableRegion; struct DraggableRegion;
...@@ -21,13 +27,11 @@ namespace views { ...@@ -21,13 +27,11 @@ namespace views {
class WebView; class WebView;
} }
class ShellWindowViews : public ShellWindow, class ShellWindowViews : public NativeShellWindow,
public views::WidgetDelegateView { public views::WidgetDelegateView {
public: public:
ShellWindowViews(Profile* profile, ShellWindowViews(ShellWindow* shell_window,
const extensions::Extension* extension, const ShellWindow::CreateParams& params);
const GURL& url,
const CreateParams& params);
bool frameless() const { return frameless_; } bool frameless() const { return frameless_; }
SkRegion* draggable_region() { return draggable_region_.get(); } SkRegion* draggable_region() { return draggable_region_.get(); }
...@@ -73,12 +77,20 @@ class ShellWindowViews : public ShellWindow, ...@@ -73,12 +77,20 @@ class ShellWindowViews : public ShellWindow,
virtual gfx::Size GetMaximumSize() OVERRIDE; virtual gfx::Size GetMaximumSize() OVERRIDE;
virtual void OnFocus() OVERRIDE; virtual void OnFocus() OVERRIDE;
Profile* profile() { return shell_window_->profile(); }
content::WebContents* web_contents() {
return shell_window_->web_contents();
}
const extensions::Extension* extension() {
return shell_window_->extension();
}
private: private:
friend class ShellWindowFrameView; friend class ShellWindowFrameView;
virtual ~ShellWindowViews(); virtual ~ShellWindowViews();
// ShellWindow implementation. // NativeShellWindow implementation.
virtual void UpdateWindowTitle() OVERRIDE; virtual void UpdateWindowTitle() OVERRIDE;
virtual void SetFullscreen(bool fullscreen) OVERRIDE; virtual void SetFullscreen(bool fullscreen) OVERRIDE;
virtual bool IsFullscreenOrPending() const OVERRIDE; virtual bool IsFullscreenOrPending() const OVERRIDE;
...@@ -87,6 +99,8 @@ class ShellWindowViews : public ShellWindow, ...@@ -87,6 +99,8 @@ class ShellWindowViews : public ShellWindow,
void OnViewWasResized(); void OnViewWasResized();
ShellWindow* shell_window_; // weak - ShellWindow owns NativeShellWindow.
views::WebView* web_view_; views::WebView* web_view_;
views::Widget* window_; views::Widget* window_;
bool is_fullscreen_; bool is_fullscreen_;
......
...@@ -283,7 +283,7 @@ void SelectFileDialogExtension::SelectFileImpl( ...@@ -283,7 +283,7 @@ void SelectFileDialogExtension::SelectFileImpl(
ShellWindow* shell_window = registry->GetShellWindowForNativeWindow( ShellWindow* shell_window = registry->GetShellWindowForNativeWindow(
owner_window); owner_window);
if (shell_window) { if (shell_window) {
base_window = shell_window; base_window = shell_window->GetBaseWindow();
tab = shell_window->tab_contents(); tab = shell_window->tab_contents();
profile_ = *i; profile_ = *i;
break; break;
......
...@@ -3050,6 +3050,7 @@ ...@@ -3050,6 +3050,7 @@
'browser/ui/crypto_module_password_dialog_openssl.cc', 'browser/ui/crypto_module_password_dialog_openssl.cc',
'browser/ui/extensions/application_launch.cc', 'browser/ui/extensions/application_launch.cc',
'browser/ui/extensions/application_launch.h', 'browser/ui/extensions/application_launch.h',
'browser/ui/extensions/native_shell_window.h',
'browser/ui/extensions/shell_window.cc', 'browser/ui/extensions/shell_window.cc',
'browser/ui/extensions/shell_window.h', 'browser/ui/extensions/shell_window.h',
'browser/ui/find_bar/find_bar.h', 'browser/ui/find_bar/find_bar.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment