Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: chrome/browser/ui/extensions/shell_window.cc

Issue 11363250: Allow Chrome apps to create Ash Panels (apps v2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PanelLayoutManager Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/extensions/shell_window.h" 5 #include "chrome/browser/ui/extensions/shell_window.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/extensions/extension_process_manager.h" 8 #include "chrome/browser/extensions/extension_process_manager.h"
9 #include "chrome/browser/extensions/extension_system.h" 9 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/browser/extensions/shell_window_geometry_cache.h" 10 #include "chrome/browser/extensions/shell_window_geometry_cache.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "content/public/browser/resource_dispatcher_host.h" 43 #include "content/public/browser/resource_dispatcher_host.h"
44 #include "content/public/browser/site_instance.h" 44 #include "content/public/browser/site_instance.h"
45 #include "content/public/browser/web_contents.h" 45 #include "content/public/browser/web_contents.h"
46 #include "content/public/browser/web_intents_dispatcher.h" 46 #include "content/public/browser/web_intents_dispatcher.h"
47 #include "content/public/common/media_stream_request.h" 47 #include "content/public/common/media_stream_request.h"
48 #include "content/public/common/renderer_preferences.h" 48 #include "content/public/common/renderer_preferences.h"
49 #include "third_party/skia/include/core/SkRegion.h" 49 #include "third_party/skia/include/core/SkRegion.h"
50 50
51 namespace app_window = extensions::api::app_window; 51 namespace app_window = extensions::api::app_window;
52 52
53 #if defined(USE_ASH)
54 #include "chrome/browser/ui/ash/shell_utility_window_ash.h"
55 #endif
56
53 using content::BrowserThread; 57 using content::BrowserThread;
54 using content::ConsoleMessageLevel; 58 using content::ConsoleMessageLevel;
55 using content::RenderViewHost; 59 using content::RenderViewHost;
56 using content::ResourceDispatcherHost; 60 using content::ResourceDispatcherHost;
57 using content::SiteInstance; 61 using content::SiteInstance;
58 using content::WebContents; 62 using content::WebContents;
59 using extensions::APIPermission; 63 using extensions::APIPermission;
60 using extensions::RequestMediaAccessPermissionHelper; 64 using extensions::RequestMediaAccessPermissionHelper;
61 65
62 namespace { 66 namespace {
63 const int kDefaultWidth = 512; 67 const int kDefaultWidth = 512;
64 const int kDefaultHeight = 384; 68 const int kDefaultHeight = 384;
65 69
66 void SuspendRenderViewHost(RenderViewHost* rvh) { 70 void SuspendRenderViewHost(RenderViewHost* rvh) {
67 DCHECK(rvh); 71 DCHECK(rvh);
68 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 72 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
69 base::Bind(&ResourceDispatcherHost::BlockRequestsForRoute, 73 base::Bind(&ResourceDispatcherHost::BlockRequestsForRoute,
70 base::Unretained(ResourceDispatcherHost::Get()), 74 base::Unretained(ResourceDispatcherHost::Get()),
71 rvh->GetProcess()->GetID(), rvh->GetRoutingID())); 75 rvh->GetProcess()->GetID(), rvh->GetRoutingID()));
72 } 76 }
73 77
74 } // namespace 78 } // namespace
75 79
76 ShellWindow::CreateParams::CreateParams() 80 ShellWindow::CreateParams::CreateParams()
77 : frame(ShellWindow::CreateParams::FRAME_CHROME), 81 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT),
82 frame(ShellWindow::FRAME_CHROME),
78 bounds(INT_MIN, INT_MIN, INT_MIN, INT_MIN), 83 bounds(INT_MIN, INT_MIN, INT_MIN, INT_MIN),
79 creator_process_id(0), hidden(false) { 84 creator_process_id(0), hidden(false) {
80 } 85 }
81 86
82 ShellWindow::CreateParams::~CreateParams() { 87 ShellWindow::CreateParams::~CreateParams() {
83 } 88 }
84 89
85 ShellWindow* ShellWindow::Create(Profile* profile, 90 ShellWindow* ShellWindow::Create(Profile* profile,
86 const extensions::Extension* extension, 91 const extensions::Extension* extension,
87 const GURL& url, 92 const GURL& url,
88 const ShellWindow::CreateParams& params) { 93 const CreateParams& params) {
89 // This object will delete itself when the window is closed. 94 // This object will delete itself when the window is closed.
90 ShellWindow* window = new ShellWindow(profile, extension); 95 ShellWindow* window = new ShellWindow(params.window_type, profile, extension);
91 window->Init(url, params); 96 window->Init(url, params);
92 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); 97 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window);
93 return window; 98 return window;
94 } 99 }
95 100
96 ShellWindow::ShellWindow(Profile* profile, 101 ShellWindow::ShellWindow(WindowType window_type,
102 Profile* profile,
97 const extensions::Extension* extension) 103 const extensions::Extension* extension)
98 : profile_(profile), 104 : profile_(profile),
99 extension_(extension), 105 extension_(extension),
100 web_contents_(NULL), 106 web_contents_(NULL),
107 window_type_(window_type),
101 ALLOW_THIS_IN_INITIALIZER_LIST( 108 ALLOW_THIS_IN_INITIALIZER_LIST(
102 extension_function_dispatcher_(profile, this)) { 109 extension_function_dispatcher_(profile, this)) {
103 } 110 }
104 111
105 void ShellWindow::Init(const GURL& url, 112 void ShellWindow::Init(const GURL& url,
106 const ShellWindow::CreateParams& params) { 113 const ShellWindow::CreateParams& params) {
107 web_contents_.reset(WebContents::Create( 114 web_contents_.reset(WebContents::Create(
108 profile(), SiteInstance::CreateForURL(profile(), url), MSG_ROUTING_NONE, 115 profile(), SiteInstance::CreateForURL(profile(), url), MSG_ROUTING_NONE,
109 NULL)); 116 NULL));
110 ConstrainedWindowTabHelper::CreateForWebContents(web_contents_.get()); 117 ConstrainedWindowTabHelper::CreateForWebContents(web_contents_.get());
(...skipping 26 matching lines...) Expand all
137 shell_window_geometry_cache(); 144 shell_window_geometry_cache();
138 gfx::Rect cached_bounds; 145 gfx::Rect cached_bounds;
139 if (cache->GetGeometry(extension()->id(), params.window_key, 146 if (cache->GetGeometry(extension()->id(), params.window_key,
140 &cached_bounds)) 147 &cached_bounds))
141 bounds = cached_bounds; 148 bounds = cached_bounds;
142 } 149 }
143 150
144 ShellWindow::CreateParams new_params = params; 151 ShellWindow::CreateParams new_params = params;
145 new_params.bounds = bounds; 152 new_params.bounds = bounds;
146 153
147 native_window_.reset(NativeShellWindow::Create(this, new_params)); 154 DCHECK(!native_window_.get());
155 #if defined(USE_ASH)
156 if (params.window_type == WINDOW_TYPE_PANEL)
157 native_window_.reset(new ShellUtilityWindowAsh(this, params));
158 #endif
159 if (!native_window_.get())
160 native_window_.reset(NativeShellWindow::Create(this, new_params));
161
148 SaveWindowPosition(); 162 SaveWindowPosition();
149 163
150 if (!params.hidden) 164 if (!params.hidden) {
151 GetBaseWindow()->Show(); 165 if (params.window_type == WINDOW_TYPE_PANEL)
jeremya 2012/11/19 00:04:24 #if defined(USE_ASH) here too. Perhaps on non-ash
stevenjb 2012/11/19 21:38:44 This logic is actually valid on any platform; pane
166 GetBaseWindow()->ShowInactive(); // Panels are not activated by default.
167 else
168 GetBaseWindow()->Show();
169 }
152 170
153 // If the new view is in the same process as the creator, block the created 171 // If the new view is in the same process as the creator, block the created
154 // RVH from loading anything until the background page has had a chance to do 172 // RVH from loading anything until the background page has had a chance to do
155 // any initialization it wants. If it's a different process, the new RVH 173 // any initialization it wants. If it's a different process, the new RVH
156 // shouldn't communicate with the background page anyway (e.g. sandboxed). 174 // shouldn't communicate with the background page anyway (e.g. sandboxed).
157 if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() == 175 if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() ==
158 params.creator_process_id) { 176 params.creator_process_id) {
159 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); 177 SuspendRenderViewHost(web_contents_->GetRenderViewHost());
160 } else { 178 } else {
161 VLOG(1) << "ShellWindow created in new process (" 179 VLOG(1) << "ShellWindow created in new process ("
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 308 }
291 309
292 BaseWindow* ShellWindow::GetBaseWindow() { 310 BaseWindow* ShellWindow::GetBaseWindow() {
293 return native_window_.get(); 311 return native_window_.get();
294 } 312 }
295 313
296 string16 ShellWindow::GetTitle() const { 314 string16 ShellWindow::GetTitle() const {
297 // WebContents::GetTitle() will return the page's URL if there's no <title> 315 // WebContents::GetTitle() will return the page's URL if there's no <title>
298 // specified. However, we'd prefer to show the name of the extension in that 316 // specified. However, we'd prefer to show the name of the extension in that
299 // case, so we directly inspect the NavigationEntry's title. 317 // case, so we directly inspect the NavigationEntry's title.
300 if (!web_contents()->GetController().GetActiveEntry() || 318 if (!web_contents() ||
319 !web_contents()->GetController().GetActiveEntry() ||
301 web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) 320 web_contents()->GetController().GetActiveEntry()->GetTitle().empty())
302 return UTF8ToUTF16(extension()->name()); 321 return UTF8ToUTF16(extension()->name());
303 string16 title = web_contents()->GetTitle(); 322 string16 title = web_contents()->GetTitle();
304 Browser::FormatTitleForDisplay(&title); 323 Browser::FormatTitleForDisplay(&title);
305 return title; 324 return title;
306 } 325 }
307 326
308 bool ShellWindow::OnMessageReceived(const IPC::Message& message) { 327 bool ShellWindow::OnMessageReceived(const IPC::Message& message) {
309 bool handled = true; 328 bool handled = true;
310 IPC_BEGIN_MESSAGE_MAP(ShellWindow, message) 329 IPC_BEGIN_MESSAGE_MAP(ShellWindow, message)
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 const extensions::DraggableRegion& region = *iter; 526 const extensions::DraggableRegion& region = *iter;
508 sk_region->op( 527 sk_region->op(
509 region.bounds.x(), 528 region.bounds.x(),
510 region.bounds.y(), 529 region.bounds.y(),
511 region.bounds.right(), 530 region.bounds.right(),
512 region.bounds.bottom(), 531 region.bounds.bottom(),
513 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); 532 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
514 } 533 }
515 return sk_region; 534 return sk_region;
516 } 535 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698