| 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(profile, extension); |
| 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(Profile* profile, |
| 97 const extensions::Extension* extension) | 98 const extensions::Extension* extension) |
| 98 : profile_(profile), | 99 : profile_(profile), |
| 99 extension_(extension), | 100 extension_(extension), |
| 100 web_contents_(NULL), | 101 web_contents_(NULL), |
| 102 window_type_(WINDOW_TYPE_DEFAULT), |
| 101 ALLOW_THIS_IN_INITIALIZER_LIST( | 103 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 102 extension_function_dispatcher_(profile, this)) { | 104 extension_function_dispatcher_(profile, this)) { |
| 103 } | 105 } |
| 104 | 106 |
| 105 void ShellWindow::Init(const GURL& url, | 107 void ShellWindow::Init(const GURL& url, |
| 106 const ShellWindow::CreateParams& params) { | 108 const ShellWindow::CreateParams& params) { |
| 109 window_type_ = params.window_type; |
| 110 |
| 107 web_contents_.reset(WebContents::Create( | 111 web_contents_.reset(WebContents::Create( |
| 108 profile(), SiteInstance::CreateForURL(profile(), url), MSG_ROUTING_NONE, | 112 profile(), SiteInstance::CreateForURL(profile(), url), MSG_ROUTING_NONE, |
| 109 NULL)); | 113 NULL)); |
| 110 ConstrainedWindowTabHelper::CreateForWebContents(web_contents_.get()); | 114 ConstrainedWindowTabHelper::CreateForWebContents(web_contents_.get()); |
| 111 FaviconTabHelper::CreateForWebContents(web_contents_.get()); | 115 FaviconTabHelper::CreateForWebContents(web_contents_.get()); |
| 112 WebIntentPickerController::CreateForWebContents(web_contents_.get()); | 116 WebIntentPickerController::CreateForWebContents(web_contents_.get()); |
| 113 | 117 |
| 114 content::WebContentsObserver::Observe(web_contents_.get()); | 118 content::WebContentsObserver::Observe(web_contents_.get()); |
| 115 web_contents_->SetDelegate(this); | 119 web_contents_->SetDelegate(this); |
| 116 chrome::SetViewType(web_contents_.get(), chrome::VIEW_TYPE_APP_SHELL); | 120 chrome::SetViewType(web_contents_.get(), chrome::VIEW_TYPE_APP_SHELL); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 if (maximum_size.height() && bounds.height() > maximum_size.height()) | 164 if (maximum_size.height() && bounds.height() > maximum_size.height()) |
| 161 bounds.set_height(maximum_size.height()); | 165 bounds.set_height(maximum_size.height()); |
| 162 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height()) | 166 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height()) |
| 163 bounds.set_height(minimum_size.height()); | 167 bounds.set_height(minimum_size.height()); |
| 164 | 168 |
| 165 new_params.bounds = bounds; | 169 new_params.bounds = bounds; |
| 166 | 170 |
| 167 native_app_window_.reset(NativeAppWindow::Create(this, new_params)); | 171 native_app_window_.reset(NativeAppWindow::Create(this, new_params)); |
| 168 OnNativeWindowChanged(); | 172 OnNativeWindowChanged(); |
| 169 | 173 |
| 170 if (!params.hidden) | 174 if (!params.hidden) { |
| 171 GetBaseWindow()->Show(); | 175 if (params.window_type == WINDOW_TYPE_PANEL) |
| 176 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. |
| 177 else |
| 178 GetBaseWindow()->Show(); |
| 179 } |
| 172 | 180 |
| 173 // If the new view is in the same process as the creator, block the created | 181 // If the new view is in the same process as the creator, block the created |
| 174 // RVH from loading anything until the background page has had a chance to do | 182 // RVH from loading anything until the background page has had a chance to do |
| 175 // any initialization it wants. If it's a different process, the new RVH | 183 // any initialization it wants. If it's a different process, the new RVH |
| 176 // shouldn't communicate with the background page anyway (e.g. sandboxed). | 184 // shouldn't communicate with the background page anyway (e.g. sandboxed). |
| 177 if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() == | 185 if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() == |
| 178 params.creator_process_id) { | 186 params.creator_process_id) { |
| 179 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); | 187 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); |
| 180 } else { | 188 } else { |
| 181 VLOG(1) << "ShellWindow created in new process (" | 189 VLOG(1) << "ShellWindow created in new process (" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 346 |
| 339 | 347 |
| 340 BaseWindow* ShellWindow::GetBaseWindow() { | 348 BaseWindow* ShellWindow::GetBaseWindow() { |
| 341 return native_app_window_.get(); | 349 return native_app_window_.get(); |
| 342 } | 350 } |
| 343 | 351 |
| 344 string16 ShellWindow::GetTitle() const { | 352 string16 ShellWindow::GetTitle() const { |
| 345 // WebContents::GetTitle() will return the page's URL if there's no <title> | 353 // WebContents::GetTitle() will return the page's URL if there's no <title> |
| 346 // specified. However, we'd prefer to show the name of the extension in that | 354 // specified. However, we'd prefer to show the name of the extension in that |
| 347 // case, so we directly inspect the NavigationEntry's title. | 355 // case, so we directly inspect the NavigationEntry's title. |
| 348 if (!web_contents()->GetController().GetActiveEntry() || | 356 if (!web_contents() || |
| 357 !web_contents()->GetController().GetActiveEntry() || |
| 349 web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) | 358 web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) |
| 350 return UTF8ToUTF16(extension()->name()); | 359 return UTF8ToUTF16(extension()->name()); |
| 351 string16 title = web_contents()->GetTitle(); | 360 string16 title = web_contents()->GetTitle(); |
| 352 Browser::FormatTitleForDisplay(&title); | 361 Browser::FormatTitleForDisplay(&title); |
| 353 return title; | 362 return title; |
| 354 } | 363 } |
| 355 | 364 |
| 356 bool ShellWindow::OnMessageReceived(const IPC::Message& message) { | 365 bool ShellWindow::OnMessageReceived(const IPC::Message& message) { |
| 357 bool handled = true; | 366 bool handled = true; |
| 358 IPC_BEGIN_MESSAGE_MAP(ShellWindow, message) | 367 IPC_BEGIN_MESSAGE_MAP(ShellWindow, message) |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 const extensions::DraggableRegion& region = *iter; | 544 const extensions::DraggableRegion& region = *iter; |
| 536 sk_region->op( | 545 sk_region->op( |
| 537 region.bounds.x(), | 546 region.bounds.x(), |
| 538 region.bounds.y(), | 547 region.bounds.y(), |
| 539 region.bounds.right(), | 548 region.bounds.right(), |
| 540 region.bounds.bottom(), | 549 region.bounds.bottom(), |
| 541 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 550 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
| 542 } | 551 } |
| 543 return sk_region; | 552 return sk_region; |
| 544 } | 553 } |
| OLD | NEW |