| 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/extensions/api/app_window/app_window_api.h" | 5 #include "chrome/browser/extensions/api/app_window/app_window_api.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/debugger/devtools_window.h" |
| 11 #include "chrome/browser/extensions/shell_window_registry.h" |
| 10 #include "chrome/browser/extensions/window_controller.h" | 12 #include "chrome/browser/extensions/window_controller.h" |
| 11 #include "chrome/browser/ui/extensions/shell_window.h" | 13 #include "chrome/browser/ui/extensions/shell_window.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 12 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/extensions/api/app_window.h" | 16 #include "chrome/common/extensions/api/app_window.h" |
| 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/notification_types.h" |
| 14 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 16 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
| 18 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 19 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
| 20 | 25 |
| 21 namespace app_window = extensions::api::app_window; | 26 namespace app_window = extensions::api::app_window; |
| 22 namespace Create = app_window::Create; | 27 namespace Create = app_window::Create; |
| 23 | 28 |
| 24 namespace extensions { | 29 namespace extensions { |
| 25 | 30 |
| 26 namespace app_window_constants { | 31 namespace app_window_constants { |
| 27 const char kInvalidWindowId[] = | 32 const char kInvalidWindowId[] = |
| 28 "The window id can not be more than 256 characters long."; | 33 "The window id can not be more than 256 characters long."; |
| 29 }; | 34 } |
| 30 | 35 |
| 31 const char kNoneFrameOption[] = "none"; | 36 const char kNoneFrameOption[] = "none"; |
| 32 const char kHtmlFrameOption[] = "experimental-html"; | 37 const char kHtmlFrameOption[] = "experimental-html"; |
| 33 | 38 |
| 39 namespace { |
| 40 |
| 41 // Opens an inspector window and delays the response to the |
| 42 // AppWindowCreateFunction until the DevToolsWindow has finished loading, and is |
| 43 // ready to stop on breakpoints in the callback. |
| 44 class DevToolsRestorer : public content::NotificationObserver { |
| 45 public: |
| 46 DevToolsRestorer(AppWindowCreateFunction* delayed_create_function, |
| 47 content::RenderViewHost* created_view) |
| 48 : delayed_create_function_(delayed_create_function) { |
| 49 DevToolsWindow* devtools_window = |
| 50 DevToolsWindow::ToggleDevToolsWindow( |
| 51 created_view, |
| 52 true /* force_open */, |
| 53 DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); |
| 54 |
| 55 registrar_.Add( |
| 56 this, |
| 57 content::NOTIFICATION_LOAD_STOP, |
| 58 content::Source<content::NavigationController>( |
| 59 &devtools_window->tab_contents()->web_contents()->GetController())); |
| 60 } |
| 61 |
| 62 protected: |
| 63 // content::NotificationObserver: |
| 64 virtual void Observe(int type, |
| 65 const content::NotificationSource& source, |
| 66 const content::NotificationDetails& details) OVERRIDE { |
| 67 DCHECK(type == content::NOTIFICATION_LOAD_STOP); |
| 68 delayed_create_function_->SendDelayedResponse(); |
| 69 delete this; |
| 70 } |
| 71 |
| 72 private: |
| 73 scoped_refptr<AppWindowCreateFunction> delayed_create_function_; |
| 74 content::NotificationRegistrar registrar_; |
| 75 }; |
| 76 |
| 77 } // namespace |
| 78 |
| 79 void AppWindowCreateFunction::SendDelayedResponse() { |
| 80 SendResponse(true); |
| 81 } |
| 82 |
| 34 bool AppWindowCreateFunction::RunImpl() { | 83 bool AppWindowCreateFunction::RunImpl() { |
| 35 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); | 84 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); |
| 36 EXTENSION_FUNCTION_VALIDATE(params.get()); | 85 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 37 | 86 |
| 38 GURL url = GetExtension()->GetResourceURL(params->url); | 87 GURL url = GetExtension()->GetResourceURL(params->url); |
| 39 // Allow absolute URLs for component apps, otherwise prepend the extension | 88 // Allow absolute URLs for component apps, otherwise prepend the extension |
| 40 // path. | 89 // path. |
| 41 if (GetExtension()->location() == extensions::Extension::COMPONENT) { | 90 if (GetExtension()->location() == extensions::Extension::COMPONENT) { |
| 42 GURL absolute = GURL(params->url); | 91 GURL absolute = GURL(params->url); |
| 43 if (absolute.has_scheme()) | 92 if (absolute.has_scheme()) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 int view_id = MSG_ROUTING_NONE; | 193 int view_id = MSG_ROUTING_NONE; |
| 145 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) | 194 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) |
| 146 view_id = created_view->GetRoutingID(); | 195 view_id = created_view->GetRoutingID(); |
| 147 | 196 |
| 148 base::DictionaryValue* result = new base::DictionaryValue; | 197 base::DictionaryValue* result = new base::DictionaryValue; |
| 149 result->Set("viewId", base::Value::CreateIntegerValue(view_id)); | 198 result->Set("viewId", base::Value::CreateIntegerValue(view_id)); |
| 150 result->Set("injectTitlebar", | 199 result->Set("injectTitlebar", |
| 151 base::Value::CreateBooleanValue(inject_html_titlebar)); | 200 base::Value::CreateBooleanValue(inject_html_titlebar)); |
| 152 result->Set("id", base::Value::CreateStringValue(shell_window->window_key())); | 201 result->Set("id", base::Value::CreateStringValue(shell_window->window_key())); |
| 153 SetResult(result); | 202 SetResult(result); |
| 203 |
| 204 if (ShellWindowRegistry::Get(profile())->HadDevToolsAttached(created_view)) { |
| 205 new DevToolsRestorer(this, created_view); |
| 206 return true; |
| 207 } |
| 208 |
| 209 SendResponse(true); |
| 154 return true; | 210 return true; |
| 155 } | 211 } |
| 156 | 212 |
| 157 } // namespace extensions | 213 } // namespace extensions |
| OLD | NEW |