| 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/time.h" | 7 #include "base/time.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/shell_window_registry.h" | |
| 10 #include "chrome/browser/extensions/window_controller.h" | 9 #include "chrome/browser/extensions/window_controller.h" |
| 11 #include "chrome/browser/ui/extensions/shell_window.h" | 10 #include "chrome/browser/ui/extensions/shell_window.h" |
| 12 #include "chrome/common/extensions/api/app_window.h" | 11 #include "chrome/common/extensions/api/app_window.h" |
| 13 #include "chrome/common/extensions/extension_error_utils.h" | |
| 14 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/url_constants.h" | 14 #include "content/public/common/url_constants.h" |
| 17 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 18 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 19 | 17 |
| 20 namespace app_window = extensions::api::app_window; | 18 namespace app_window = extensions::api::app_window; |
| 21 namespace Create = app_window::Create; | 19 namespace Create = app_window::Create; |
| 22 | 20 |
| 23 namespace extensions { | 21 namespace extensions { |
| 24 | 22 |
| 25 namespace app_window_constants { | |
| 26 const char kNoAssociatedShellWindow[] = | |
| 27 "The context from which the function was called did not have an " | |
| 28 "associated shell window."; | |
| 29 }; | |
| 30 | |
| 31 bool AppWindowExtensionFunction::RunImpl() { | |
| 32 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); | |
| 33 CHECK(registry); | |
| 34 content::RenderViewHost* rvh = render_view_host(); | |
| 35 if (!rvh) | |
| 36 // No need to set an error, since we won't return to the caller anyway if | |
| 37 // there's no RVH. | |
| 38 return false; | |
| 39 ShellWindow* window = registry->GetShellWindowForRenderViewHost(rvh); | |
| 40 if (!window) { | |
| 41 error_ = app_window_constants::kNoAssociatedShellWindow; | |
| 42 return false; | |
| 43 } | |
| 44 return RunWithWindow(window); | |
| 45 } | |
| 46 | |
| 47 const char kNoneFrameOption[] = "none"; | 23 const char kNoneFrameOption[] = "none"; |
| 48 | 24 |
| 49 bool AppWindowCreateFunction::RunImpl() { | 25 bool AppWindowCreateFunction::RunImpl() { |
| 50 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); | 26 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); |
| 51 EXTENSION_FUNCTION_VALIDATE(params.get()); | 27 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 52 | 28 |
| 53 GURL url = GetExtension()->GetResourceURL(params->url); | 29 GURL url = GetExtension()->GetResourceURL(params->url); |
| 54 | 30 |
| 55 // TODO(jeremya): figure out a way to pass the opening WebContents through to | 31 // TODO(jeremya): figure out a way to pass the opening WebContents through to |
| 56 // ShellWindow::Create so we can set the opener at create time rather than | 32 // ShellWindow::Create so we can set the opener at create time rather than |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 ShellWindow::Create(profile(), GetExtension(), url, create_params); | 82 ShellWindow::Create(profile(), GetExtension(), url, create_params); |
| 107 shell_window->GetBaseWindow()->Show(); | 83 shell_window->GetBaseWindow()->Show(); |
| 108 | 84 |
| 109 content::WebContents* created_contents = shell_window->web_contents(); | 85 content::WebContents* created_contents = shell_window->web_contents(); |
| 110 int view_id = created_contents->GetRenderViewHost()->GetRoutingID(); | 86 int view_id = created_contents->GetRenderViewHost()->GetRoutingID(); |
| 111 | 87 |
| 112 SetResult(base::Value::CreateIntegerValue(view_id)); | 88 SetResult(base::Value::CreateIntegerValue(view_id)); |
| 113 return true; | 89 return true; |
| 114 } | 90 } |
| 115 | 91 |
| 116 bool AppWindowFocusFunction::RunWithWindow(ShellWindow* window) { | |
| 117 window->GetBaseWindow()->Activate(); | |
| 118 return true; | |
| 119 } | |
| 120 | |
| 121 bool AppWindowMaximizeFunction::RunWithWindow(ShellWindow* window) { | |
| 122 window->GetBaseWindow()->Maximize(); | |
| 123 return true; | |
| 124 } | |
| 125 | |
| 126 bool AppWindowMinimizeFunction::RunWithWindow(ShellWindow* window) { | |
| 127 window->GetBaseWindow()->Minimize(); | |
| 128 return true; | |
| 129 } | |
| 130 | |
| 131 bool AppWindowRestoreFunction::RunWithWindow(ShellWindow* window) { | |
| 132 window->GetBaseWindow()->Restore(); | |
| 133 return true; | |
| 134 } | |
| 135 | |
| 136 } // namespace extensions | 92 } // namespace extensions |
| OLD | NEW |