 Chromium Code Reviews
 Chromium Code Reviews Issue 11363250:
  Allow Chrome apps to create Ash Panels (apps v2)  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 11363250:
  Allow Chrome apps to create Ash Panels (apps v2)  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| 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 Loading... | |
| 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_panel_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::CreateParams::FRAME_CHROME), | |
| 78 bounds(INT_MIN, INT_MIN, INT_MIN, INT_MIN), | 83 bounds(INT_MIN, INT_MIN, INT_MIN, INT_MIN), | 
| 79 restore_position(true), restore_size(true), | 84 restore_position(true), restore_size(true), | 
| 80 creator_process_id(0), hidden(false) { | 85 creator_process_id(0), hidden(false) { | 
| 81 } | 86 } | 
| 82 | 87 | 
| 83 ShellWindow::CreateParams::~CreateParams() { | 88 ShellWindow::CreateParams::~CreateParams() { | 
| 84 } | 89 } | 
| 85 | 90 | 
| 86 ShellWindow* ShellWindow::Create(Profile* profile, | 91 ShellWindow* ShellWindow::Create(Profile* profile, | 
| 87 const extensions::Extension* extension, | 92 const extensions::Extension* extension, | 
| 88 const GURL& url, | 93 const GURL& url, | 
| 89 const ShellWindow::CreateParams& params) { | 94 const CreateParams& params) { | 
| 90 // This object will delete itself when the window is closed. | 95 // This object will delete itself when the window is closed. | 
| 91 ShellWindow* window = new ShellWindow(profile, extension); | 96 ShellWindow* window = new ShellWindow(params.window_type, profile, extension); | 
| 92 window->Init(url, params); | 97 window->Init(url, params); | 
| 93 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); | 98 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); | 
| 94 return window; | 99 return window; | 
| 95 } | 100 } | 
| 96 | 101 | 
| 97 ShellWindow::ShellWindow(Profile* profile, | 102 ShellWindow::ShellWindow(WindowType window_type, | 
| 103 Profile* profile, | |
| 98 const extensions::Extension* extension) | 104 const extensions::Extension* extension) | 
| 99 : profile_(profile), | 105 : profile_(profile), | 
| 100 extension_(extension), | 106 extension_(extension), | 
| 101 web_contents_(NULL), | 107 web_contents_(NULL), | 
| 108 window_type_(window_type), | |
| 102 ALLOW_THIS_IN_INITIALIZER_LIST( | 109 ALLOW_THIS_IN_INITIALIZER_LIST( | 
| 103 extension_function_dispatcher_(profile, this)) { | 110 extension_function_dispatcher_(profile, this)) { | 
| 104 } | 111 } | 
| 105 | 112 | 
| 106 void ShellWindow::Init(const GURL& url, | 113 void ShellWindow::Init(const GURL& url, | 
| 107 const ShellWindow::CreateParams& params) { | 114 const ShellWindow::CreateParams& params) { | 
| 108 web_contents_.reset(WebContents::Create( | 115 web_contents_.reset(WebContents::Create( | 
| 109 profile(), SiteInstance::CreateForURL(profile(), url), MSG_ROUTING_NONE, | 116 profile(), SiteInstance::CreateForURL(profile(), url), MSG_ROUTING_NONE, | 
| 110 NULL)); | 117 NULL)); | 
| 111 ConstrainedWindowTabHelper::CreateForWebContents(web_contents_.get()); | 118 ConstrainedWindowTabHelper::CreateForWebContents(web_contents_.get()); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 bounds.set_origin(cached_bounds.origin()); | 151 bounds.set_origin(cached_bounds.origin()); | 
| 145 if (params.restore_size) | 152 if (params.restore_size) | 
| 146 bounds.set_size(cached_bounds.size()); | 153 bounds.set_size(cached_bounds.size()); | 
| 147 } | 154 } | 
| 148 } | 155 } | 
| 149 } | 156 } | 
| 150 | 157 | 
| 151 ShellWindow::CreateParams new_params = params; | 158 ShellWindow::CreateParams new_params = params; | 
| 152 new_params.bounds = bounds; | 159 new_params.bounds = bounds; | 
| 153 | 160 | 
| 154 native_window_.reset(NativeShellWindow::Create(this, new_params)); | 161 DCHECK(!native_window_.get()); | 
| 162 #if defined(USE_ASH) | |
| 163 if (params.window_type == WINDOW_TYPE_PANEL) | |
| 164 native_window_.reset(new ShellPanelAsh(this, params)); | |
| 165 #endif | |
| 166 if (!native_window_.get()) | |
| 167 native_window_.reset(NativeShellWindow::Create(this, new_params)); | |
| 168 | |
| 155 SaveWindowPosition(); | 169 SaveWindowPosition(); | 
| 156 | 170 | 
| 157 if (!params.hidden) | 171 if (!params.hidden) { | 
| 158 GetBaseWindow()->Show(); | 172 if (params.window_type != WINDOW_TYPE_PANEL) | 
| 
jeremya
2012/11/15 01:09:25
Shouldn't this be == then?
 
stevenjb
2012/11/16 23:42:40
Yes. Done.
 | |
| 173 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. | |
| 174 else | |
| 175 GetBaseWindow()->Show(); | |
| 176 } | |
| 159 | 177 | 
| 160 // If the new view is in the same process as the creator, block the created | 178 // If the new view is in the same process as the creator, block the created | 
| 161 // RVH from loading anything until the background page has had a chance to do | 179 // RVH from loading anything until the background page has had a chance to do | 
| 162 // any initialization it wants. If it's a different process, the new RVH | 180 // any initialization it wants. If it's a different process, the new RVH | 
| 163 // shouldn't communicate with the background page anyway (e.g. sandboxed). | 181 // shouldn't communicate with the background page anyway (e.g. sandboxed). | 
| 164 if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() == | 182 if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() == | 
| 165 params.creator_process_id) { | 183 params.creator_process_id) { | 
| 166 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); | 184 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); | 
| 167 } else { | 185 } else { | 
| 168 VLOG(1) << "ShellWindow created in new process (" | 186 VLOG(1) << "ShellWindow created in new process (" | 
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 } | 315 } | 
| 298 | 316 | 
| 299 BaseWindow* ShellWindow::GetBaseWindow() { | 317 BaseWindow* ShellWindow::GetBaseWindow() { | 
| 300 return native_window_.get(); | 318 return native_window_.get(); | 
| 301 } | 319 } | 
| 302 | 320 | 
| 303 string16 ShellWindow::GetTitle() const { | 321 string16 ShellWindow::GetTitle() const { | 
| 304 // WebContents::GetTitle() will return the page's URL if there's no <title> | 322 // WebContents::GetTitle() will return the page's URL if there's no <title> | 
| 305 // specified. However, we'd prefer to show the name of the extension in that | 323 // specified. However, we'd prefer to show the name of the extension in that | 
| 306 // case, so we directly inspect the NavigationEntry's title. | 324 // case, so we directly inspect the NavigationEntry's title. | 
| 307 if (!web_contents()->GetController().GetActiveEntry() || | 325 if (!web_contents() || | 
| 326 !web_contents()->GetController().GetActiveEntry() || | |
| 308 web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) | 327 web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) | 
| 309 return UTF8ToUTF16(extension()->name()); | 328 return UTF8ToUTF16(extension()->name()); | 
| 310 string16 title = web_contents()->GetTitle(); | 329 string16 title = web_contents()->GetTitle(); | 
| 311 Browser::FormatTitleForDisplay(&title); | 330 Browser::FormatTitleForDisplay(&title); | 
| 312 return title; | 331 return title; | 
| 313 } | 332 } | 
| 314 | 333 | 
| 315 bool ShellWindow::OnMessageReceived(const IPC::Message& message) { | 334 bool ShellWindow::OnMessageReceived(const IPC::Message& message) { | 
| 316 bool handled = true; | 335 bool handled = true; | 
| 317 IPC_BEGIN_MESSAGE_MAP(ShellWindow, message) | 336 IPC_BEGIN_MESSAGE_MAP(ShellWindow, message) | 
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 const extensions::DraggableRegion& region = *iter; | 533 const extensions::DraggableRegion& region = *iter; | 
| 515 sk_region->op( | 534 sk_region->op( | 
| 516 region.bounds.x(), | 535 region.bounds.x(), | 
| 517 region.bounds.y(), | 536 region.bounds.y(), | 
| 518 region.bounds.right(), | 537 region.bounds.right(), | 
| 519 region.bounds.bottom(), | 538 region.bounds.bottom(), | 
| 520 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 539 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 
| 521 } | 540 } | 
| 522 return sk_region; | 541 return sk_region; | 
| 523 } | 542 } | 
| OLD | NEW |