15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/browser/api/app_current_window_internal/app_current_window_internal_api.h"
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/command_line.h"
81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/browser/app_window/app_window.h"
91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/browser/app_window/app_window_client.h"
101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/browser/app_window/app_window_registry.h"
1103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "extensions/browser/app_window/native_app_window.h"
1203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "extensions/browser/app_window/size_constraints.h"
131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/common/api/app_current_window_internal.h"
14c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "extensions/common/features/simple_feature.h"
1546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "extensions/common/permissions/permissions_data.h"
16a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "extensions/common/switches.h"
173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "third_party/skia/include/core/SkRegion.h"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace app_current_window_internal =
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    extensions::core_api::app_current_window_internal;
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace Show = app_current_window_internal::Show;
231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace SetBounds = app_current_window_internal::SetBounds;
24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace SetSizeConstraints = app_current_window_internal::SetSizeConstraints;
251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace SetIcon = app_current_window_internal::SetIcon;
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace SetBadgeIcon = app_current_window_internal::SetBadgeIcon;
27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace SetShape = app_current_window_internal::SetShape;
281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace SetAlwaysOnTop = app_current_window_internal::SetAlwaysOnTop;
291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccinamespace SetVisibleOnAllWorkspaces =
301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    app_current_window_internal::SetVisibleOnAllWorkspaces;
313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)using app_current_window_internal::Bounds;
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)using app_current_window_internal::Region;
341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)using app_current_window_internal::RegionRect;
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)using app_current_window_internal::SizeConstraints;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace extensions {
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const char kNoAssociatedAppWindow[] =
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "The context from which the function was called did not have an "
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    "associated app window.";
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
45a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)const char kDevChannelOnly[] =
46a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    "This function is currently only available in the Dev channel.";
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)const char kRequiresFramelessWindow[] =
49a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    "This function requires a frameless window (frame:none).";
50a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
51a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)const char kAlwaysOnTopPermission[] =
52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    "The \"app.window.alwaysOnTop\" permission is required.";
53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)const char kInvalidParameters[] = "Invalid parameters.";
55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)const int kUnboundedSize = SizeConstraints::kUnboundedSize;
57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void GetBoundsFields(const Bounds& bounds_spec, gfx::Rect* bounds) {
59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (bounds_spec.left)
60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    bounds->set_x(*bounds_spec.left);
61a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (bounds_spec.top)
62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    bounds->set_y(*bounds_spec.top);
63a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (bounds_spec.width)
64a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    bounds->set_width(*bounds_spec.width);
65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (bounds_spec.height)
66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    bounds->set_height(*bounds_spec.height);
67a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
68a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
69a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copy the constraint value from the API to our internal representation of
70a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// content size constraints. A value of zero resets the constraints. The insets
71a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// are used to transform window constraints to content constraints.
72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void GetConstraintWidth(const scoped_ptr<int>& width,
73a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                        const gfx::Insets& insets,
74a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                        gfx::Size* size) {
75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!width.get())
76a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
77a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  size->set_width(*width > 0 ? std::max(0, *width - insets.width())
79a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                             : kUnboundedSize);
80a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
81a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
82a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void GetConstraintHeight(const scoped_ptr<int>& height,
83a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                         const gfx::Insets& insets,
84a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                         gfx::Size* size) {
85a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!height.get())
86a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
87a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  size->set_height(*height > 0 ? std::max(0, *height - insets.height())
89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                               : kUnboundedSize);
90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace bounds {
95a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
96a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)enum BoundsType {
97a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  INNER_BOUNDS,
98a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  OUTER_BOUNDS,
99a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DEPRECATED_BOUNDS,
100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  INVALID_TYPE
101a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
103a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)const char kInnerBoundsType[] = "innerBounds";
104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)const char kOuterBoundsType[] = "outerBounds";
105a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)const char kDeprecatedBoundsType[] = "bounds";
106a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)BoundsType GetBoundsType(const std::string& type_as_string) {
108a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (type_as_string == kInnerBoundsType)
109a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return INNER_BOUNDS;
110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  else if (type_as_string == kOuterBoundsType)
111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return OUTER_BOUNDS;
112a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  else if (type_as_string == kDeprecatedBoundsType)
113a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return DEPRECATED_BOUNDS;
114a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  else
115a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return INVALID_TYPE;
116a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
117a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
118a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace bounds
119a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liubool AppCurrentWindowInternalExtensionFunction::RunSync() {
1211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  AppWindowRegistry* registry = AppWindowRegistry::Get(browser_context());
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(registry);
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::RenderViewHost* rvh = render_view_host();
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!rvh)
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // No need to set an error, since we won't return to the caller anyway if
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // there's no RVH.
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  AppWindow* window = registry->GetAppWindowForRenderViewHost(rvh);
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!window) {
1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    error_ = kNoAssociatedAppWindow;
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return RunWithWindow(window);
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool AppCurrentWindowInternalFocusFunction::RunWithWindow(AppWindow* window) {
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  window->GetBaseWindow()->Activate();
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool AppCurrentWindowInternalFullscreenFunction::RunWithWindow(
1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AppWindow* window) {
143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  window->Fullscreen();
144c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return true;
145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
146c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool AppCurrentWindowInternalMaximizeFunction::RunWithWindow(
1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AppWindow* window) {
149c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  window->Maximize();
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool AppCurrentWindowInternalMinimizeFunction::RunWithWindow(
1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AppWindow* window) {
155c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  window->Minimize();
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool AppCurrentWindowInternalRestoreFunction::RunWithWindow(AppWindow* window) {
160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  window->Restore();
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool AppCurrentWindowInternalDrawAttentionFunction::RunWithWindow(
1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AppWindow* window) {
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  window->GetBaseWindow()->FlashFrame(true);
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool AppCurrentWindowInternalClearAttentionFunction::RunWithWindow(
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AppWindow* window) {
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  window->GetBaseWindow()->FlashFrame(false);
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool AppCurrentWindowInternalShowFunction::RunWithWindow(AppWindow* window) {
1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<Show::Params> params(Show::Params::Create(*args_));
1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CHECK(params.get());
1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (params->focused && !*params->focused)
1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    window->Show(AppWindow::SHOW_INACTIVE);
1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  else
1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    window->Show(AppWindow::SHOW_ACTIVE);
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool AppCurrentWindowInternalHideFunction::RunWithWindow(AppWindow* window) {
187f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  window->Hide();
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool AppCurrentWindowInternalSetBoundsFunction::RunWithWindow(
1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AppWindow* window) {
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<SetBounds::Params> params(SetBounds::Params::Create(*args_));
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CHECK(params.get());
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
196a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bounds::BoundsType bounds_type = bounds::GetBoundsType(params->bounds_type);
197a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (bounds_type == bounds::INVALID_TYPE) {
198a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    NOTREACHED();
199a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    error_ = kInvalidParameters;
200f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return false;
201f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
202f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
203a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Start with the current bounds, and change any values that are specified in
204a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // the incoming parameters.
205a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  gfx::Rect original_window_bounds = window->GetBaseWindow()->GetBounds();
206a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  gfx::Rect window_bounds = original_window_bounds;
207a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  gfx::Insets frame_insets = window->GetBaseWindow()->GetFrameInsets();
208a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const Bounds& bounds_spec = params->bounds;
209a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
210a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  switch (bounds_type) {
211a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    case bounds::DEPRECATED_BOUNDS: {
212a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      // We need to maintain backcompatibility with a bug on Windows and
213a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      // ChromeOS, which sets the position of the window but the size of the
214a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      // content.
215a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      if (bounds_spec.left)
216a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        window_bounds.set_x(*bounds_spec.left);
217a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      if (bounds_spec.top)
218a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        window_bounds.set_y(*bounds_spec.top);
219a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      if (bounds_spec.width)
220a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        window_bounds.set_width(*bounds_spec.width + frame_insets.width());
221a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      if (bounds_spec.height)
222a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        window_bounds.set_height(*bounds_spec.height + frame_insets.height());
223a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      break;
224a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    }
225a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    case bounds::OUTER_BOUNDS: {
226a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      GetBoundsFields(bounds_spec, &window_bounds);
227a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      break;
228a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    }
229a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    case bounds::INNER_BOUNDS: {
230a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      window_bounds.Inset(frame_insets);
231a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      GetBoundsFields(bounds_spec, &window_bounds);
232a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      window_bounds.Inset(-frame_insets);
233a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      break;
234a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    }
235a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    default:
236a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      NOTREACHED();
237a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
238a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
239a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (original_window_bounds != window_bounds) {
240a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    if (original_window_bounds.size() != window_bounds.size()) {
24103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      SizeConstraints constraints(
24203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)          SizeConstraints::AddFrameToConstraints(
243a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)              window->GetBaseWindow()->GetContentMinimumSize(), frame_insets),
24403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)          SizeConstraints::AddFrameToConstraints(
245a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)              window->GetBaseWindow()->GetContentMaximumSize(), frame_insets));
246a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
247a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      window_bounds.set_size(constraints.ClampSize(window_bounds.size()));
248a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    }
249a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
250a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    window->GetBaseWindow()->SetBounds(window_bounds);
251a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
252a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
2531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  return true;
2541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
2551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
256a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool AppCurrentWindowInternalSetSizeConstraintsFunction::RunWithWindow(
2575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AppWindow* window) {
258a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  scoped_ptr<SetSizeConstraints::Params> params(
259a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      SetSizeConstraints::Params::Create(*args_));
2601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  CHECK(params.get());
2611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
262a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bounds::BoundsType bounds_type = bounds::GetBoundsType(params->bounds_type);
263a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (bounds_type != bounds::INNER_BOUNDS &&
264a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      bounds_type != bounds::OUTER_BOUNDS) {
265a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    NOTREACHED();
266a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    error_ = kInvalidParameters;
267f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return false;
268f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
269f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
270a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  gfx::Size original_min_size =
271a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      window->GetBaseWindow()->GetContentMinimumSize();
272a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  gfx::Size original_max_size =
273a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      window->GetBaseWindow()->GetContentMaximumSize();
274a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  gfx::Size min_size = original_min_size;
275a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  gfx::Size max_size = original_max_size;
2761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  const app_current_window_internal::SizeConstraints& constraints =
27703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      params->constraints;
278a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
279a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Use the frame insets to convert window size constraints to content size
280a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // constraints.
281a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  gfx::Insets insets;
282a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (bounds_type == bounds::OUTER_BOUNDS)
283a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    insets = window->GetBaseWindow()->GetFrameInsets();
284a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
285a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetConstraintWidth(constraints.min_width, insets, &min_size);
286a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetConstraintWidth(constraints.max_width, insets, &max_size);
287a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetConstraintHeight(constraints.min_height, insets, &min_size);
288a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetConstraintHeight(constraints.max_height, insets, &max_size);
289a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
290a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (min_size != original_min_size || max_size != original_max_size)
291a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    window->SetContentSizeConstraints(min_size, max_size);
292a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
2931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  return true;
2941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
2951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool AppCurrentWindowInternalSetIconFunction::RunWithWindow(AppWindow* window) {
2971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (AppWindowClient::Get()->IsCurrentChannelOlderThanDev() &&
2985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      extension()->location() != extensions::Manifest::COMPONENT) {
299a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    error_ = kDevChannelOnly;
3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return false;
3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<SetIcon::Params> params(SetIcon::Params::Create(*args_));
3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CHECK(params.get());
3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The |icon_url| parameter may be a blob url (e.g. an image fetched with an
3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // XMLHttpRequest) or a resource url.
3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  GURL url(params->icon_url);
3082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!url.is_valid())
3095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    url = extension()->GetResourceURL(params->icon_url);
3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  window->SetAppIconUrl(url);
3122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return true;
3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool AppCurrentWindowInternalSetBadgeIconFunction::RunWithWindow(
3165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AppWindow* window) {
3171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (AppWindowClient::Get()->IsCurrentChannelOlderThanDev()) {
3185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    error_ = kDevChannelOnly;
3195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return false;
3205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
3215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<SetBadgeIcon::Params> params(SetBadgeIcon::Params::Create(*args_));
3235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CHECK(params.get());
3245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The |icon_url| parameter may be a blob url (e.g. an image fetched with an
3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // XMLHttpRequest) or a resource url.
3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GURL url(params->icon_url);
3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!url.is_valid() && !params->icon_url.empty())
3285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    url = extension()->GetResourceURL(params->icon_url);
3295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  window->SetBadgeIconUrl(url);
3315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return true;
3325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool AppCurrentWindowInternalClearBadgeFunction::RunWithWindow(
3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AppWindow* window) {
3361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (AppWindowClient::Get()->IsCurrentChannelOlderThanDev()) {
3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    error_ = kDevChannelOnly;
3385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return false;
3395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
3405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  window->ClearBadge();
3425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return true;
3435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
345f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)bool AppCurrentWindowInternalSetShapeFunction::RunWithWindow(
3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AppWindow* window) {
34768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
348a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!window->GetBaseWindow()->IsFrameless()) {
349a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    error_ = kRequiresFramelessWindow;
350a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return false;
351a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
352a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
353f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<SetShape::Params> params(
354f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      SetShape::Params::Create(*args_));
355f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  const Region& shape = params->region;
3563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
3573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Build a region from the supplied list of rects.
3583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // If |rects| is missing, then the input region is removed. This clears the
3593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // input region so that the entire window accepts input events.
3603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // To specify an empty input region (so the window ignores all input),
3613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // |rects| should be an empty list.
3623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  scoped_ptr<SkRegion> region(new SkRegion);
363f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (shape.rects) {
3643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    for (std::vector<linked_ptr<RegionRect> >::const_iterator i =
365f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)             shape.rects->begin();
366f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)         i != shape.rects->end();
3673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)         ++i) {
3683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const RegionRect& inputRect = **i;
3693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      int32_t x = inputRect.left;
3703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      int32_t y = inputRect.top;
3713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      int32_t width = inputRect.width;
3723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      int32_t height = inputRect.height;
3733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
3743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      SkIRect rect = SkIRect::MakeXYWH(x, y, width, height);
3753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      region->op(rect, SkRegion::kUnion_Op);
3763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    }
3773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  } else {
3783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    region.reset(NULL);
3793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
3803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
381f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  window->UpdateShape(region.Pass());
3823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
3833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  return true;
3843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
3853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
3864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)bool AppCurrentWindowInternalSetAlwaysOnTopFunction::RunWithWindow(
3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AppWindow* window) {
3885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (!extension()->permissions_data()->HasAPIPermission(
389a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          extensions::APIPermission::kAlwaysOnTopWindows)) {
390a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    error_ = kAlwaysOnTopPermission;
391f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return false;
392f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
393f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
3944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<SetAlwaysOnTop::Params> params(
3954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      SetAlwaysOnTop::Params::Create(*args_));
3964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  CHECK(params.get());
397f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  window->SetAlwaysOnTop(params->always_on_top);
3984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return true;
3994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
4004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
4011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool AppCurrentWindowInternalSetVisibleOnAllWorkspacesFunction::RunWithWindow(
4021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    AppWindow* window) {
4031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (AppWindowClient::Get()->IsCurrentChannelOlderThanDev()) {
4041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    error_ = kDevChannelOnly;
4051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    return false;
4061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
4071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
4081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<SetVisibleOnAllWorkspaces::Params> params(
4091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      SetVisibleOnAllWorkspaces::Params::Create(*args_));
4101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  CHECK(params.get());
4111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  window->GetBaseWindow()->SetVisibleOnAllWorkspaces(params->always_visible);
4121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return true;
4131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
4141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace extensions
416