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

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

Issue 11238055: Re-open DevTools windows for PackagedApps if they are reloaded with DevTools open. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: more encapsulation, self-nit unit test code, add expected FAILS_ for debug builds Created 8 years, 2 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
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 "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(created_view,
benwells 2012/10/24 03:24:08 Nit: created_view on next line
tapted 2012/10/24 04:03:57 Done.
51 true /* force_open */,
52 DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE);
53
54 registrar_.Add(this,
benwells 2012/10/24 03:24:08 Maybe if this goes on the next line you won't need
tapted 2012/10/24 04:03:57 Done.
55 content::NOTIFICATION_LOAD_STOP,
56 content::Source<content::NavigationController>(
57 &devtools_window->tab_contents()
58 ->web_contents()->GetController()));
59 }
benwells 2012/10/24 03:24:08 Blank line before protected:
tapted 2012/10/24 04:03:57 Done.
60 protected:
61 // content::NotificationObserver:
62 virtual void Observe(int type,
63 const content::NotificationSource& source,
64 const content::NotificationDetails& details) OVERRIDE {
65 DCHECK(type == content::NOTIFICATION_LOAD_STOP);
66 delayed_create_function_->SendDelayedResponse();
67 delete this;
68 }
69 private:
benwells 2012/10/24 03:24:08 Blank line before private:
tapted 2012/10/24 04:03:57 Done.
70 scoped_refptr<AppWindowCreateFunction> delayed_create_function_;
71 content::NotificationRegistrar registrar_;
72 };
73
74 } // namespace
75
76 void AppWindowCreateFunction::SendDelayedResponse() {
77 SendResponse(true);
78 }
79
34 bool AppWindowCreateFunction::RunImpl() { 80 bool AppWindowCreateFunction::RunImpl() {
35 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); 81 scoped_ptr<Create::Params> params(Create::Params::Create(*args_));
36 EXTENSION_FUNCTION_VALIDATE(params.get()); 82 EXTENSION_FUNCTION_VALIDATE(params.get());
37 83
38 GURL url = GetExtension()->GetResourceURL(params->url); 84 GURL url = GetExtension()->GetResourceURL(params->url);
39 // Allow absolute URLs for component apps, otherwise prepend the extension 85 // Allow absolute URLs for component apps, otherwise prepend the extension
40 // path. 86 // path.
41 if (GetExtension()->location() == extensions::Extension::COMPONENT) { 87 if (GetExtension()->location() == extensions::Extension::COMPONENT) {
42 GURL absolute = GURL(params->url); 88 GURL absolute = GURL(params->url);
43 if (absolute.has_scheme()) 89 if (absolute.has_scheme())
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 int view_id = MSG_ROUTING_NONE; 190 int view_id = MSG_ROUTING_NONE;
145 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) 191 if (create_params.creator_process_id == created_view->GetProcess()->GetID())
146 view_id = created_view->GetRoutingID(); 192 view_id = created_view->GetRoutingID();
147 193
148 base::DictionaryValue* result = new base::DictionaryValue; 194 base::DictionaryValue* result = new base::DictionaryValue;
149 result->Set("viewId", base::Value::CreateIntegerValue(view_id)); 195 result->Set("viewId", base::Value::CreateIntegerValue(view_id));
150 result->Set("injectTitlebar", 196 result->Set("injectTitlebar",
151 base::Value::CreateBooleanValue(inject_html_titlebar)); 197 base::Value::CreateBooleanValue(inject_html_titlebar));
152 result->Set("id", base::Value::CreateStringValue(shell_window->window_key())); 198 result->Set("id", base::Value::CreateStringValue(shell_window->window_key()));
153 SetResult(result); 199 SetResult(result);
200
201 if (ShellWindowRegistry::Get(profile())->HadDevToolsAttached(created_view)) {
202 new DevToolsRestorer(this, created_view);
203 return true;
204 }
205
206 SendResponse(true);
154 return true; 207 return true;
155 } 208 }
156 209
157 } // namespace extensions 210 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698