Chromium Code Reviews| 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 "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/extension_process_manager.h" | 9 #include "chrome/browser/extensions/extension_process_manager.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" | 10 #include "chrome/browser/extensions/extension_system.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 DCHECK(rvh); | 67 DCHECK(rvh); |
| 68 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 68 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 69 base::Bind(&ResourceDispatcherHost::BlockRequestsForRoute, | 69 base::Bind(&ResourceDispatcherHost::BlockRequestsForRoute, |
| 70 base::Unretained(ResourceDispatcherHost::Get()), | 70 base::Unretained(ResourceDispatcherHost::Get()), |
| 71 rvh->GetProcess()->GetID(), rvh->GetRoutingID())); | 71 rvh->GetProcess()->GetID(), rvh->GetRoutingID())); |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 ShellWindow::CreateParams::CreateParams() | 76 ShellWindow::CreateParams::CreateParams() |
| 77 : frame(ShellWindow::CreateParams::FRAME_CHROME), | 77 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), |
| 78 frame(ShellWindow::FRAME_CHROME), | |
| 78 bounds(INT_MIN, INT_MIN, INT_MIN, INT_MIN), | 79 bounds(INT_MIN, INT_MIN, INT_MIN, INT_MIN), |
| 79 creator_process_id(0), hidden(false) { | 80 creator_process_id(0), hidden(false) { |
| 80 } | 81 } |
| 81 | 82 |
| 82 ShellWindow::CreateParams::~CreateParams() { | 83 ShellWindow::CreateParams::~CreateParams() { |
| 83 } | 84 } |
| 84 | 85 |
| 85 ShellWindow* ShellWindow::Create(Profile* profile, | 86 ShellWindow* ShellWindow::Create(Profile* profile, |
| 86 const extensions::Extension* extension, | 87 const extensions::Extension* extension, |
| 87 const GURL& url, | 88 const GURL& url, |
| 88 const ShellWindow::CreateParams& params) { | 89 const CreateParams& params) { |
| 89 // This object will delete itself when the window is closed. | 90 // This object will delete itself when the window is closed. |
| 90 ShellWindow* window = new ShellWindow(profile, extension); | 91 ShellWindow* window = new ShellWindow(params.window_type, profile, extension); |
|
jeremya
2012/11/29 02:49:05
Probably better to read this out in Init() rather
stevenjb
2012/11/29 03:11:26
Agreed, done.
| |
| 91 window->Init(url, params); | 92 window->Init(url, params); |
| 92 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); | 93 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); |
| 93 return window; | 94 return window; |
| 94 } | 95 } |
| 95 | 96 |
| 96 ShellWindow::ShellWindow(Profile* profile, | 97 ShellWindow::ShellWindow(WindowType window_type, |
| 98 Profile* profile, | |
| 97 const extensions::Extension* extension) | 99 const extensions::Extension* extension) |
| 98 : profile_(profile), | 100 : profile_(profile), |
| 99 extension_(extension), | 101 extension_(extension), |
| 100 web_contents_(NULL), | 102 web_contents_(NULL), |
| 103 window_type_(window_type), | |
| 101 ALLOW_THIS_IN_INITIALIZER_LIST( | 104 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 102 extension_function_dispatcher_(profile, this)) { | 105 extension_function_dispatcher_(profile, this)) { |
| 103 } | 106 } |
| 104 | 107 |
| 105 void ShellWindow::Init(const GURL& url, | 108 void ShellWindow::Init(const GURL& url, |
| 106 const ShellWindow::CreateParams& params) { | 109 const ShellWindow::CreateParams& params) { |
| 107 web_contents_.reset(WebContents::Create( | 110 web_contents_.reset(WebContents::Create( |
| 108 profile(), SiteInstance::CreateForURL(profile(), url), MSG_ROUTING_NONE, | 111 profile(), SiteInstance::CreateForURL(profile(), url), MSG_ROUTING_NONE, |
| 109 NULL)); | 112 NULL)); |
| 110 ConstrainedWindowTabHelper::CreateForWebContents(web_contents_.get()); | 113 ConstrainedWindowTabHelper::CreateForWebContents(web_contents_.get()); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 139 &cached_bounds)) | 142 &cached_bounds)) |
| 140 bounds = cached_bounds; | 143 bounds = cached_bounds; |
| 141 } | 144 } |
| 142 | 145 |
| 143 ShellWindow::CreateParams new_params = params; | 146 ShellWindow::CreateParams new_params = params; |
| 144 new_params.bounds = bounds; | 147 new_params.bounds = bounds; |
| 145 | 148 |
| 146 native_app_window_.reset(NativeAppWindow::Create(this, new_params)); | 149 native_app_window_.reset(NativeAppWindow::Create(this, new_params)); |
| 147 OnNativeWindowChanged(); | 150 OnNativeWindowChanged(); |
| 148 | 151 |
| 149 if (!params.hidden) | 152 if (!params.hidden) { |
| 150 GetBaseWindow()->Show(); | 153 if (params.window_type == WINDOW_TYPE_PANEL) |
| 154 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. | |
| 155 else | |
| 156 GetBaseWindow()->Show(); | |
| 157 } | |
| 151 | 158 |
| 152 // If the new view is in the same process as the creator, block the created | 159 // If the new view is in the same process as the creator, block the created |
| 153 // RVH from loading anything until the background page has had a chance to do | 160 // RVH from loading anything until the background page has had a chance to do |
| 154 // any initialization it wants. If it's a different process, the new RVH | 161 // any initialization it wants. If it's a different process, the new RVH |
| 155 // shouldn't communicate with the background page anyway (e.g. sandboxed). | 162 // shouldn't communicate with the background page anyway (e.g. sandboxed). |
| 156 if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() == | 163 if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() == |
| 157 params.creator_process_id) { | 164 params.creator_process_id) { |
| 158 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); | 165 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); |
| 159 } else { | 166 } else { |
| 160 VLOG(1) << "ShellWindow created in new process (" | 167 VLOG(1) << "ShellWindow created in new process (" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 | 324 |
| 318 | 325 |
| 319 BaseWindow* ShellWindow::GetBaseWindow() { | 326 BaseWindow* ShellWindow::GetBaseWindow() { |
| 320 return native_app_window_.get(); | 327 return native_app_window_.get(); |
| 321 } | 328 } |
| 322 | 329 |
| 323 string16 ShellWindow::GetTitle() const { | 330 string16 ShellWindow::GetTitle() const { |
| 324 // WebContents::GetTitle() will return the page's URL if there's no <title> | 331 // WebContents::GetTitle() will return the page's URL if there's no <title> |
| 325 // specified. However, we'd prefer to show the name of the extension in that | 332 // specified. However, we'd prefer to show the name of the extension in that |
| 326 // case, so we directly inspect the NavigationEntry's title. | 333 // case, so we directly inspect the NavigationEntry's title. |
| 327 if (!web_contents()->GetController().GetActiveEntry() || | 334 if (!web_contents() || |
| 335 !web_contents()->GetController().GetActiveEntry() || | |
| 328 web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) | 336 web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) |
| 329 return UTF8ToUTF16(extension()->name()); | 337 return UTF8ToUTF16(extension()->name()); |
| 330 string16 title = web_contents()->GetTitle(); | 338 string16 title = web_contents()->GetTitle(); |
| 331 Browser::FormatTitleForDisplay(&title); | 339 Browser::FormatTitleForDisplay(&title); |
| 332 return title; | 340 return title; |
| 333 } | 341 } |
| 334 | 342 |
| 335 bool ShellWindow::OnMessageReceived(const IPC::Message& message) { | 343 bool ShellWindow::OnMessageReceived(const IPC::Message& message) { |
| 336 bool handled = true; | 344 bool handled = true; |
| 337 IPC_BEGIN_MESSAGE_MAP(ShellWindow, message) | 345 IPC_BEGIN_MESSAGE_MAP(ShellWindow, message) |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 const extensions::DraggableRegion& region = *iter; | 522 const extensions::DraggableRegion& region = *iter; |
| 515 sk_region->op( | 523 sk_region->op( |
| 516 region.bounds.x(), | 524 region.bounds.x(), |
| 517 region.bounds.y(), | 525 region.bounds.y(), |
| 518 region.bounds.right(), | 526 region.bounds.right(), |
| 519 region.bounds.bottom(), | 527 region.bounds.bottom(), |
| 520 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 528 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
| 521 } | 529 } |
| 522 return sk_region; | 530 return sk_region; |
| 523 } | 531 } |
| OLD | NEW |