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

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: Address feedback Created 8 years 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 "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
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 22 matching lines...) Expand all
139 &cached_bounds)) 143 &cached_bounds))
140 bounds = cached_bounds; 144 bounds = cached_bounds;
141 } 145 }
142 146
143 ShellWindow::CreateParams new_params = params; 147 ShellWindow::CreateParams new_params = params;
144 new_params.bounds = bounds; 148 new_params.bounds = bounds;
145 149
146 native_app_window_.reset(NativeAppWindow::Create(this, new_params)); 150 native_app_window_.reset(NativeAppWindow::Create(this, new_params));
147 OnNativeWindowChanged(); 151 OnNativeWindowChanged();
148 152
149 if (!params.hidden) 153 if (!params.hidden) {
150 GetBaseWindow()->Show(); 154 if (params.window_type == WINDOW_TYPE_PANEL)
155 GetBaseWindow()->ShowInactive(); // Panels are not activated by default.
156 else
157 GetBaseWindow()->Show();
158 }
151 159
152 // If the new view is in the same process as the creator, block the created 160 // 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 161 // 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 162 // 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). 163 // shouldn't communicate with the background page anyway (e.g. sandboxed).
156 if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() == 164 if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() ==
157 params.creator_process_id) { 165 params.creator_process_id) {
158 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); 166 SuspendRenderViewHost(web_contents_->GetRenderViewHost());
159 } else { 167 } else {
160 VLOG(1) << "ShellWindow created in new process (" 168 VLOG(1) << "ShellWindow created in new process ("
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 325
318 326
319 BaseWindow* ShellWindow::GetBaseWindow() { 327 BaseWindow* ShellWindow::GetBaseWindow() {
320 return native_app_window_.get(); 328 return native_app_window_.get();
321 } 329 }
322 330
323 string16 ShellWindow::GetTitle() const { 331 string16 ShellWindow::GetTitle() const {
324 // WebContents::GetTitle() will return the page's URL if there's no <title> 332 // 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 333 // specified. However, we'd prefer to show the name of the extension in that
326 // case, so we directly inspect the NavigationEntry's title. 334 // case, so we directly inspect the NavigationEntry's title.
327 if (!web_contents()->GetController().GetActiveEntry() || 335 if (!web_contents() ||
336 !web_contents()->GetController().GetActiveEntry() ||
328 web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) 337 web_contents()->GetController().GetActiveEntry()->GetTitle().empty())
329 return UTF8ToUTF16(extension()->name()); 338 return UTF8ToUTF16(extension()->name());
330 string16 title = web_contents()->GetTitle(); 339 string16 title = web_contents()->GetTitle();
331 Browser::FormatTitleForDisplay(&title); 340 Browser::FormatTitleForDisplay(&title);
332 return title; 341 return title;
333 } 342 }
334 343
335 bool ShellWindow::OnMessageReceived(const IPC::Message& message) { 344 bool ShellWindow::OnMessageReceived(const IPC::Message& message) {
336 bool handled = true; 345 bool handled = true;
337 IPC_BEGIN_MESSAGE_MAP(ShellWindow, message) 346 IPC_BEGIN_MESSAGE_MAP(ShellWindow, message)
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 const extensions::DraggableRegion& region = *iter; 523 const extensions::DraggableRegion& region = *iter;
515 sk_region->op( 524 sk_region->op(
516 region.bounds.x(), 525 region.bounds.x(),
517 region.bounds.y(), 526 region.bounds.y(),
518 region.bounds.right(), 527 region.bounds.right(),
519 region.bounds.bottom(), 528 region.bounds.bottom(),
520 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); 529 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
521 } 530 }
522 return sk_region; 531 return sk_region;
523 } 532 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698