| 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" | 9 #include "chrome/browser/extensions/shell_window_registry.h" |
| 10 #include "chrome/browser/extensions/window_controller.h" | 10 #include "chrome/browser/extensions/window_controller.h" |
| 11 #include "chrome/browser/ui/extensions/shell_window.h" | 11 #include "chrome/browser/ui/extensions/shell_window.h" |
| 12 #include "chrome/common/extensions/api/app_window.h" | 12 #include "chrome/common/extensions/api/app_window.h" |
| 13 #include "chrome/common/extensions/extension_error_utils.h" | 13 #include "chrome/common/extensions/extension_error_utils.h" |
| 14 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
| 19 | 19 |
| 20 namespace app_window = extensions::api::app_window; | 20 namespace app_window = extensions::api::app_window; |
| 21 namespace Create = app_window::Create; | 21 namespace Create = app_window::Create; |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 | 24 |
| 25 namespace app_window_constants { | 25 namespace app_window_constants { |
| 26 const char kNoAssociatedShellWindow[] = | 26 const char kNoAssociatedShellWindow[] = |
| 27 "The context from which the function was called did not have an " | 27 "The context from which the function was called did not have an " |
| 28 "associated shell window."; | 28 "associated shell window."; |
| 29 const char kInvalidWindowId[] = |
| 30 "The window id can not be more than 256 characters long."; |
| 29 }; | 31 }; |
| 30 | 32 |
| 31 bool AppWindowExtensionFunction::RunImpl() { | 33 bool AppWindowExtensionFunction::RunImpl() { |
| 32 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); | 34 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); |
| 33 CHECK(registry); | 35 CHECK(registry); |
| 34 content::RenderViewHost* rvh = render_view_host(); | 36 content::RenderViewHost* rvh = render_view_host(); |
| 35 if (!rvh) | 37 if (!rvh) |
| 36 // No need to set an error, since we won't return to the caller anyway if | 38 // No need to set an error, since we won't return to the caller anyway if |
| 37 // there's no RVH. | 39 // there's no RVH. |
| 38 return false; | 40 return false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 51 EXTENSION_FUNCTION_VALIDATE(params.get()); | 53 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 52 | 54 |
| 53 GURL url = GetExtension()->GetResourceURL(params->url); | 55 GURL url = GetExtension()->GetResourceURL(params->url); |
| 54 | 56 |
| 55 // TODO(jeremya): figure out a way to pass the opening WebContents through to | 57 // 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 | 58 // ShellWindow::Create so we can set the opener at create time rather than |
| 57 // with a hack in AppWindowCustomBindings::GetView(). | 59 // with a hack in AppWindowCustomBindings::GetView(). |
| 58 ShellWindow::CreateParams create_params; | 60 ShellWindow::CreateParams create_params; |
| 59 app_window::CreateWindowOptions* options = params->options.get(); | 61 app_window::CreateWindowOptions* options = params->options.get(); |
| 60 if (options) { | 62 if (options) { |
| 61 if (options->width.get()) | 63 if (options->id.get()) { |
| 62 create_params.bounds.set_width(*options->width.get()); | 64 // TODO(mek): use URL if no id specified? |
| 63 if (options->height.get()) | 65 // Limit length of id to 256 characters. |
| 64 create_params.bounds.set_height(*options->height.get()); | 66 if (options->id->length() > 256) { |
| 65 if (options->left.get()) | 67 error_ = app_window_constants::kInvalidWindowId; |
| 66 create_params.bounds.set_x(*options->left.get()); | 68 return false; |
| 67 if (options->top.get()) | 69 } |
| 68 create_params.bounds.set_y(*options->top.get()); | 70 |
| 71 create_params.window_key = *options->id; |
| 72 } |
| 73 |
| 74 if (options->default_width.get()) |
| 75 create_params.bounds.set_width(*options->default_width.get()); |
| 76 if (options->default_height.get()) |
| 77 create_params.bounds.set_height(*options->default_height.get()); |
| 78 if (options->default_left.get()) |
| 79 create_params.bounds.set_x(*options->default_left.get()); |
| 80 if (options->default_top.get()) |
| 81 create_params.bounds.set_y(*options->default_top.get()); |
| 82 |
| 83 |
| 84 if (options->width.get() || options->height.get()) { |
| 85 if (options->width.get()) |
| 86 create_params.bounds.set_width(*options->width.get()); |
| 87 if (options->height.get()) |
| 88 create_params.bounds.set_height(*options->height.get()); |
| 89 create_params.restore_size = false; |
| 90 } |
| 91 |
| 92 if (options->left.get() || options->top.get()) { |
| 93 if (options->left.get()) |
| 94 create_params.bounds.set_x(*options->left.get()); |
| 95 if (options->top.get()) |
| 96 create_params.bounds.set_y(*options->top.get()); |
| 97 create_params.restore_position = false; |
| 98 } |
| 69 | 99 |
| 70 if (options->frame.get()) { | 100 if (options->frame.get()) { |
| 71 create_params.frame = *options->frame == kNoneFrameOption ? | 101 create_params.frame = *options->frame == kNoneFrameOption ? |
| 72 ShellWindow::CreateParams::FRAME_NONE : | 102 ShellWindow::CreateParams::FRAME_NONE : |
| 73 ShellWindow::CreateParams::FRAME_CHROME; | 103 ShellWindow::CreateParams::FRAME_CHROME; |
| 74 } | 104 } |
| 75 | 105 |
| 76 gfx::Size& minimum_size = create_params.minimum_size; | 106 gfx::Size& minimum_size = create_params.minimum_size; |
| 77 if (options->min_width.get()) | 107 if (options->min_width.get()) |
| 78 minimum_size.set_width(*options->min_width); | 108 minimum_size.set_width(*options->min_width); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 window->GetBaseWindow()->Minimize(); | 157 window->GetBaseWindow()->Minimize(); |
| 128 return true; | 158 return true; |
| 129 } | 159 } |
| 130 | 160 |
| 131 bool AppWindowRestoreFunction::RunWithWindow(ShellWindow* window) { | 161 bool AppWindowRestoreFunction::RunWithWindow(ShellWindow* window) { |
| 132 window->GetBaseWindow()->Restore(); | 162 window->GetBaseWindow()->Restore(); |
| 133 return true; | 163 return true; |
| 134 } | 164 } |
| 135 | 165 |
| 136 } // namespace extensions | 166 } // namespace extensions |
| OLD | NEW |