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

Side by Side Diff: chrome/browser/extensions/api/app_window/app_window_api.cc

Issue 214243003: Remove some chrome dependencies from extensions app_window API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months 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/extensions/api/app_window/app_window_api.h" 5 #include "chrome/browser/extensions/api/app_window/app_window_api.h"
6 6
7 #include "apps/app_window.h" 7 #include "apps/app_window.h"
8 #include "apps/app_window_contents.h" 8 #include "apps/app_window_contents.h"
9 #include "apps/app_window_registry.h" 9 #include "apps/app_window_registry.h"
10 #include "apps/apps_client.h" 10 #include "apps/apps_client.h"
11 #include "apps/ui/native_app_window.h" 11 #include "apps/ui/native_app_window.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/app_mode/app_mode_utils.h"
18 #include "chrome/browser/devtools/devtools_window.h" 17 #include "chrome/browser/devtools/devtools_window.h"
19 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
20 #include "chrome/browser/extensions/window_controller.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/common/extensions/api/app_window.h" 18 #include "chrome/common/extensions/api/app_window.h"
23 #include "chrome/common/extensions/features/feature_channel.h" 19 #include "chrome/common/extensions/features/feature_channel.h"
24 #include "content/public/browser/notification_registrar.h" 20 #include "content/public/browser/notification_registrar.h"
25 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
26 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
27 #include "content/public/browser/render_view_host.h" 23 #include "content/public/browser/render_view_host.h"
28 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
29 #include "content/public/common/url_constants.h" 25 #include "content/public/common/url_constants.h"
30 #include "extensions/browser/extensions_browser_client.h" 26 #include "extensions/browser/extensions_browser_client.h"
27 #include "extensions/browser/image_util.h"
31 #include "extensions/common/switches.h" 28 #include "extensions/common/switches.h"
32 #include "third_party/skia/include/core/SkColor.h" 29 #include "third_party/skia/include/core/SkColor.h"
33 #include "ui/base/ui_base_types.h" 30 #include "ui/base/ui_base_types.h"
34 #include "ui/gfx/rect.h" 31 #include "ui/gfx/rect.h"
35 #include "url/gurl.h" 32 #include "url/gurl.h"
36 33
37 #if defined(USE_ASH)
38 #include "ash/shell.h"
39 #include "ui/aura/window.h"
40 #include "ui/aura/window_event_dispatcher.h"
41 #endif
42
43 using apps::AppWindow; 34 using apps::AppWindow;
44 35
45 namespace app_window = extensions::api::app_window; 36 namespace app_window = extensions::api::app_window;
46 namespace Create = app_window::Create; 37 namespace Create = app_window::Create;
47 38
48 namespace extensions { 39 namespace extensions {
49 40
50 namespace app_window_constants { 41 namespace app_window_constants {
51 const char kInvalidWindowId[] = 42 const char kInvalidWindowId[] =
52 "The window id can not be more than 256 characters long."; 43 "The window id can not be more than 256 characters long.";
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 create_params.window_key = *options->id; 173 create_params.window_key = *options->id;
183 174
184 if (options->singleton && *options->singleton == false) { 175 if (options->singleton && *options->singleton == false) {
185 WriteToConsole( 176 WriteToConsole(
186 content::CONSOLE_MESSAGE_LEVEL_WARNING, 177 content::CONSOLE_MESSAGE_LEVEL_WARNING,
187 "The 'singleton' option in chrome.apps.window.create() is deprecated!" 178 "The 'singleton' option in chrome.apps.window.create() is deprecated!"
188 " Change your code to no longer rely on this."); 179 " Change your code to no longer rely on this.");
189 } 180 }
190 181
191 if (!options->singleton || *options->singleton) { 182 if (!options->singleton || *options->singleton) {
192 AppWindow* window = apps::AppWindowRegistry::Get(GetProfile()) 183 AppWindow* window = apps::AppWindowRegistry::Get(browser_context())
193 ->GetAppWindowForAppAndKey( 184 ->GetAppWindowForAppAndKey(
194 extension_id(), create_params.window_key); 185 extension_id(), create_params.window_key);
195 if (window) { 186 if (window) {
196 content::RenderViewHost* created_view = 187 content::RenderViewHost* created_view =
197 window->web_contents()->GetRenderViewHost(); 188 window->web_contents()->GetRenderViewHost();
198 int view_id = MSG_ROUTING_NONE; 189 int view_id = MSG_ROUTING_NONE;
199 if (render_view_host_->GetProcess()->GetID() == 190 if (render_view_host_->GetProcess()->GetID() ==
200 created_view->GetProcess()->GetID()) { 191 created_view->GetProcess()->GetID()) {
201 view_id = created_view->GetRoutingID(); 192 view_id = created_view->GetRoutingID();
202 } 193 }
203 194
204 if (options->focused.get() && !*options->focused.get()) 195 if (options->focused.get() && !*options->focused.get())
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 break; 259 break;
269 } 260 }
270 } 261 }
271 } 262 }
272 263
273 UpdateFrameOptionsForChannel(&create_params); 264 UpdateFrameOptionsForChannel(&create_params);
274 265
275 create_params.creator_process_id = 266 create_params.creator_process_id =
276 render_view_host_->GetProcess()->GetID(); 267 render_view_host_->GetProcess()->GetID();
277 268
278 AppWindow* app_window = 269 AppWindow* app_window = apps::AppsClient::Get()->CreateAppWindow(
279 apps::AppsClient::Get()->CreateAppWindow(GetProfile(), GetExtension()); 270 browser_context(), GetExtension());
280 app_window->Init( 271 app_window->Init(
281 url, new apps::AppWindowContentsImpl(app_window), create_params); 272 url, new apps::AppWindowContentsImpl(app_window), create_params);
282 273
283 if (chrome::IsRunningInForcedAppMode()) 274 if (ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode())
284 app_window->ForcedFullscreen(); 275 app_window->ForcedFullscreen();
285 276
286 content::RenderViewHost* created_view = 277 content::RenderViewHost* created_view =
287 app_window->web_contents()->GetRenderViewHost(); 278 app_window->web_contents()->GetRenderViewHost();
288 int view_id = MSG_ROUTING_NONE; 279 int view_id = MSG_ROUTING_NONE;
289 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) 280 if (create_params.creator_process_id == created_view->GetProcess()->GetID())
290 view_id = created_view->GetRoutingID(); 281 view_id = created_view->GetRoutingID();
291 282
292 base::DictionaryValue* result = new base::DictionaryValue; 283 base::DictionaryValue* result = new base::DictionaryValue;
293 result->Set("viewId", new base::FundamentalValue(view_id)); 284 result->Set("viewId", new base::FundamentalValue(view_id));
294 result->Set("injectTitlebar", 285 result->Set("injectTitlebar",
295 new base::FundamentalValue(inject_html_titlebar_)); 286 new base::FundamentalValue(inject_html_titlebar_));
296 result->Set("id", new base::StringValue(app_window->window_key())); 287 result->Set("id", new base::StringValue(app_window->window_key()));
297 app_window->GetSerializedState(result); 288 app_window->GetSerializedState(result);
298 SetResult(result); 289 SetResult(result);
299 290
300 if (apps::AppWindowRegistry::Get(GetProfile()) 291 if (apps::AppWindowRegistry::Get(browser_context())
301 ->HadDevToolsAttached(created_view)) { 292 ->HadDevToolsAttached(created_view)) {
302 new DevToolsRestorer(this, created_view); 293 new DevToolsRestorer(this, created_view);
303 return true; 294 return true;
304 } 295 }
305 296
306 SendResponse(true); 297 SendResponse(true);
307 return true; 298 return true;
308 } 299 }
309 300
310 bool AppWindowCreateFunction::GetBoundsSpec( 301 bool AppWindowCreateFunction::GetBoundsSpec(
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 if (options.frame->as_frame_options->type) 451 if (options.frame->as_frame_options->type)
461 create_params->frame = 452 create_params->frame =
462 GetFrameFromString(*options.frame->as_frame_options->type); 453 GetFrameFromString(*options.frame->as_frame_options->type);
463 454
464 if (options.frame->as_frame_options->color.get()) { 455 if (options.frame->as_frame_options->color.get()) {
465 if (create_params->frame != AppWindow::FRAME_CHROME) { 456 if (create_params->frame != AppWindow::FRAME_CHROME) {
466 error_ = app_window_constants::kColorWithFrameNone; 457 error_ = app_window_constants::kColorWithFrameNone;
467 return false; 458 return false;
468 } 459 }
469 460
470 if (ExtensionActionFunction::ParseCSSColorString( 461 if (image_util::ParseCSSColorString(*options.frame->as_frame_options->color,
471 *options.frame->as_frame_options->color, 462 &create_params->frame_color)) {
472 &create_params->frame_color)) {
473 create_params->has_frame_color = true; 463 create_params->has_frame_color = true;
474 return true; 464 return true;
475 } 465 }
476 466
477 error_ = app_window_constants::kInvalidColorSpecification; 467 error_ = app_window_constants::kInvalidColorSpecification;
478 return false; 468 return false;
479 } 469 }
480 470
481 return true; 471 return true;
482 } 472 }
483 473
484 void AppWindowCreateFunction::UpdateFrameOptionsForChannel( 474 void AppWindowCreateFunction::UpdateFrameOptionsForChannel(
485 apps::AppWindow::CreateParams* create_params) { 475 apps::AppWindow::CreateParams* create_params) {
486 #if defined(OS_WIN) 476 #if defined(OS_WIN)
487 if (create_params->frame == AppWindow::FRAME_CHROME && 477 if (create_params->frame == AppWindow::FRAME_CHROME &&
488 GetCurrentChannel() > chrome::VersionInfo::CHANNEL_DEV) { 478 GetCurrentChannel() > chrome::VersionInfo::CHANNEL_DEV) {
489 // If not on trunk or dev channel, always use the standard white frame. 479 // If not on trunk or dev channel, always use the standard white frame.
490 // TODO(benwells): Remove this code once we get agreement to use the new 480 // TODO(benwells): Remove this code once we get agreement to use the new
491 // native style frame. 481 // native style frame.
492 create_params->has_frame_color = true; 482 create_params->has_frame_color = true;
493 create_params->frame_color = SK_ColorWHITE; 483 create_params->frame_color = SK_ColorWHITE;
494 } 484 }
495 #endif 485 #endif
496 } 486 }
497 487
498 } // namespace extensions 488 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698