summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc28
-rw-r--r--chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.h10
-rw-r--r--chrome/browser/extensions/api/app_window/app_window_apitest.cc54
-rw-r--r--chrome/browser/extensions/platform_app_browsertest_util.cc6
-rw-r--r--chrome/browser/extensions/platform_app_browsertest_util.h5
-rw-r--r--chrome/browser/extensions/shell_window_registry.cc6
-rw-r--r--chrome/browser/extensions/shell_window_registry.h3
-rw-r--r--chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc6
-rw-r--r--chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h1
-rw-r--r--chrome/browser/ui/extensions/shell_window.cc5
-rw-r--r--chrome/browser/ui/extensions/shell_window.h8
-rw-r--r--chrome/common/extensions/api/app_current_window_internal.idl1
-rw-r--r--chrome/common/extensions/api/app_window.idl5
-rw-r--r--chrome/test/data/extensions/platform_apps/windows_api_set_icon/background.js11
-rw-r--r--chrome/test/data/extensions/platform_apps/windows_api_set_icon/icon.png0
-rw-r--r--chrome/test/data/extensions/platform_apps/windows_api_set_icon/manifest.json9
-rw-r--r--chrome/test/data/extensions/platform_apps/windows_api_set_icon/test.html1
17 files changed, 159 insertions, 0 deletions
diff --git a/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc b/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc
index 46c1fa8..15f0191 100644
--- a/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc
+++ b/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc
@@ -4,13 +4,17 @@
#include "chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.h"
+#include "base/command_line.h"
#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/browser/ui/extensions/shell_window.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/app_current_window_internal.h"
+#include "chrome/common/extensions/api/app_window.h"
namespace SetBounds = extensions::api::app_current_window_internal::SetBounds;
using extensions::api::app_current_window_internal::Bounds;
+namespace SetIcon = extensions::api::app_current_window_internal::SetIcon;
namespace extensions {
@@ -20,6 +24,10 @@ const char kNoAssociatedShellWindow[] =
"The context from which the function was called did not have an "
"associated shell window.";
+const char kNoExperimental[] =
+ "This function is experimental. Use --enable-experimental-extension-apis "
+ "to enable.";
+
} // namespace
bool AppCurrentWindowInternalExtensionFunction::RunImpl() {
@@ -105,4 +113,24 @@ bool AppCurrentWindowInternalSetBoundsFunction::RunWithWindow(
return true;
}
+bool AppCurrentWindowInternalSetIconFunction::RunWithWindow(
+ ShellWindow* window) {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableExperimentalExtensionApis)) {
+ error_ = kNoExperimental;
+ return false;
+ }
+
+ scoped_ptr<SetIcon::Params> params(SetIcon::Params::Create(*args_));
+ CHECK(params.get());
+ // The |icon_url| parameter may be a blob url (e.g. an image fetched with an
+ // XMLHttpRequest) or a resource url.
+ GURL url(params->icon_url);
+ if (!url.is_valid())
+ url = GetExtension()->GetResourceURL(params->icon_url);
+
+ window->SetAppIconUrl(url);
+ return true;
+}
+
} // namespace extensions
diff --git a/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.h b/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.h
index 2b19a24..b32bb22 100644
--- a/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.h
+++ b/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.h
@@ -111,6 +111,16 @@ class AppCurrentWindowInternalSetBoundsFunction
virtual bool RunWithWindow(ShellWindow* window) OVERRIDE;
};
+class AppCurrentWindowInternalSetIconFunction
+ : public AppCurrentWindowInternalExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION_NAME("app.currentWindowInternal.setIcon");
+
+ protected:
+ virtual ~AppCurrentWindowInternalSetIconFunction() {}
+ virtual bool RunWithWindow(ShellWindow* window) OVERRIDE;
+};
+
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_APP_CURRENT_WINDOW_INTERNAL_APP_CURRENT_WINDOW_INTERNAL_API_H_
diff --git a/chrome/browser/extensions/api/app_window/app_window_apitest.cc b/chrome/browser/extensions/api/app_window/app_window_apitest.cc
index dadffbd..99bfb18 100644
--- a/chrome/browser/extensions/api/app_window/app_window_apitest.cc
+++ b/chrome/browser/extensions/api/app_window/app_window_apitest.cc
@@ -5,10 +5,47 @@
#include "base/string_number_conversions.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/extensions/platform_app_browsertest_util.h"
+#include "chrome/browser/extensions/shell_window_registry.h"
+#include "chrome/browser/ui/base_window.h"
+#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/browser/ui/extensions/shell_window.h"
+#include "chrome/test/base/testing_profile.h"
#include "ui/gfx/rect.h"
+namespace {
+
+class TestShellWindowRegistryObserver
+ : public extensions::ShellWindowRegistry::Observer {
+ public:
+ explicit TestShellWindowRegistryObserver(Profile* profile)
+ : profile_(profile),
+ icon_updates_(0) {
+ extensions::ShellWindowRegistry::Get(profile_)->AddObserver(this);
+ }
+ virtual ~TestShellWindowRegistryObserver() {
+ extensions::ShellWindowRegistry::Get(profile_)->RemoveObserver(this);
+ }
+
+ // Overridden from ShellWindowRegistry::Observer:
+ virtual void OnShellWindowAdded(ShellWindow* shell_window) {}
+ virtual void OnShellWindowIconChanged(ShellWindow* shell_window) {
+ ++icon_updates_;
+ }
+ virtual void OnShellWindowRemoved(ShellWindow* shell_window) {
+ }
+
+ int icon_updates() { return icon_updates_; }
+
+ private:
+ Profile* profile_;
+ int icon_updates_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestShellWindowRegistryObserver);
+};
+
+} // namespace
+
namespace extensions {
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiBounds) {
@@ -37,6 +74,23 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiBounds) {
ASSERT_TRUE(success_listener.WaitUntilSatisfied());
}
+// Tests chrome.app.window.setIcon.
+IN_PROC_BROWSER_TEST_F(ExperimentalPlatformAppBrowserTest, WindowsApiSetIcon) {
+ scoped_ptr<TestShellWindowRegistryObserver> test_observer(
+ new TestShellWindowRegistryObserver(browser()->profile()));
+ ExtensionTestMessageListener listener("IconSet", false);
+ LoadAndLaunchPlatformApp("windows_api_set_icon");
+ EXPECT_EQ(0, test_observer->icon_updates());
+
+ ASSERT_TRUE(listener.WaitUntilSatisfied());
+
+ ShellWindow* shell_window = GetFirstShellWindow();
+ ASSERT_TRUE(shell_window);
+ EXPECT_NE(std::string::npos,
+ shell_window->app_icon_url().spec().find("icon.png"));
+ EXPECT_EQ(1, test_observer->icon_updates());
+}
+
// TODO(asargent) - Fix onMinimzed event on OSX (crbug.com/162793) and figure
// out what to do about the fact that minimize events don't work under ubuntu
// unity (crbug.com/162794 and https://bugs.launchpad.net/unity/+bug/998073).
diff --git a/chrome/browser/extensions/platform_app_browsertest_util.cc b/chrome/browser/extensions/platform_app_browsertest_util.cc
index 9883088..4611c0a 100644
--- a/chrome/browser/extensions/platform_app_browsertest_util.cc
+++ b/chrome/browser/extensions/platform_app_browsertest_util.cc
@@ -152,4 +152,10 @@ void PlatformAppBrowserTest::CloseShellWindow(ShellWindow* window) {
destroyed_observer.Wait();
}
+void ExperimentalPlatformAppBrowserTest::SetUpCommandLine(
+ CommandLine* command_line) {
+ PlatformAppBrowserTest::SetUpCommandLine(command_line);
+ command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
+}
+
} // namespace extensions
diff --git a/chrome/browser/extensions/platform_app_browsertest_util.h b/chrome/browser/extensions/platform_app_browsertest_util.h
index 3d3a2a7..5383c0c 100644
--- a/chrome/browser/extensions/platform_app_browsertest_util.h
+++ b/chrome/browser/extensions/platform_app_browsertest_util.h
@@ -68,6 +68,11 @@ class PlatformAppBrowserTest : public ExtensionApiTest {
void CloseShellWindow(ShellWindow* window);
};
+class ExperimentalPlatformAppBrowserTest : public PlatformAppBrowserTest {
+ public:
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
+};
+
}
#endif // CHROME_BROWSER_EXTENSIONS_PLATFORM_APP_BROWSERTEST_UTIL_H_
diff --git a/chrome/browser/extensions/shell_window_registry.cc b/chrome/browser/extensions/shell_window_registry.cc
index 279fb74..1bf1fae 100644
--- a/chrome/browser/extensions/shell_window_registry.cc
+++ b/chrome/browser/extensions/shell_window_registry.cc
@@ -58,6 +58,12 @@ void ShellWindowRegistry::AddShellWindow(ShellWindow* shell_window) {
FOR_EACH_OBSERVER(Observer, observers_, OnShellWindowAdded(shell_window));
}
+void ShellWindowRegistry::ShellWindowIconChanged(ShellWindow* shell_window) {
+ shell_windows_.insert(shell_window);
+ FOR_EACH_OBSERVER(Observer, observers_,
+ OnShellWindowIconChanged(shell_window));
+}
+
void ShellWindowRegistry::RemoveShellWindow(ShellWindow* shell_window) {
shell_windows_.erase(shell_window);
FOR_EACH_OBSERVER(Observer, observers_, OnShellWindowRemoved(shell_window));
diff --git a/chrome/browser/extensions/shell_window_registry.h b/chrome/browser/extensions/shell_window_registry.h
index 7379bf7..cdd2909 100644
--- a/chrome/browser/extensions/shell_window_registry.h
+++ b/chrome/browser/extensions/shell_window_registry.h
@@ -39,6 +39,8 @@ class ShellWindowRegistry : public ProfileKeyedService,
public:
// Called just after a shell window was added.
virtual void OnShellWindowAdded(ShellWindow* shell_window) = 0;
+ // Called when the window icon changes.
+ virtual void OnShellWindowIconChanged(ShellWindow* shell_window) = 0;
// Called just after a shell window was removed.
virtual void OnShellWindowRemoved(ShellWindow* shell_window) = 0;
@@ -58,6 +60,7 @@ class ShellWindowRegistry : public ProfileKeyedService,
static ShellWindowRegistry* Get(Profile* profile);
void AddShellWindow(ShellWindow* shell_window);
+ void ShellWindowIconChanged(ShellWindow* shell_window);
void RemoveShellWindow(ShellWindow* shell_window);
void AddObserver(Observer* observer);
diff --git a/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc b/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc
index 12d8750..7c9c2d1 100644
--- a/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc
+++ b/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc
@@ -253,6 +253,12 @@ void ShellWindowLauncherController::OnShellWindowAdded(
owner_->SetItemStatus(launcher_id, status);
}
+void ShellWindowLauncherController::OnShellWindowIconChanged(
+ ShellWindow* shell_window) {
+ // TODO(stevenjb): Fetch and set the launcher icon using
+ // shell_window->app_icon_url().
+}
+
void ShellWindowLauncherController::OnShellWindowRemoved(
ShellWindow* shell_window) {
// Do nothing here; shell_window->window() has allready been deleted and
diff --git a/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h b/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h
index 7311a92..b154bcd 100644
--- a/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h
+++ b/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h
@@ -40,6 +40,7 @@ class ShellWindowLauncherController
// Overridden from ShellWindowRegistry::Observer:
virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE;
+ virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE;
virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE;
// Overriden from aura::WindowObserver:
diff --git a/chrome/browser/ui/extensions/shell_window.cc b/chrome/browser/ui/extensions/shell_window.cc
index 0a7d23f..f81723a 100644
--- a/chrome/browser/ui/extensions/shell_window.cc
+++ b/chrome/browser/ui/extensions/shell_window.cc
@@ -94,6 +94,11 @@ ShellWindow* ShellWindow::Create(Profile* profile,
return window;
}
+void ShellWindow::SetAppIconUrl(const GURL& url) {
+ app_icon_url_ = url;
+ extensions::ShellWindowRegistry::Get(profile_)->ShellWindowIconChanged(this);
+}
+
ShellWindow::ShellWindow(Profile* profile,
const extensions::Extension* extension)
: profile_(profile),
diff --git a/chrome/browser/ui/extensions/shell_window.h b/chrome/browser/ui/extensions/shell_window.h
index f13fbb9..7423ae7 100644
--- a/chrome/browser/ui/extensions/shell_window.h
+++ b/chrome/browser/ui/extensions/shell_window.h
@@ -83,6 +83,9 @@ class ShellWindow : public content::NotificationObserver,
const GURL& url,
const CreateParams& params);
+ // Specifies a url for the launcher icon.
+ void SetAppIconUrl(const GURL& icon_url);
+
// Convert draggable regions in raw format to SkRegion format. Caller is
// responsible for deleting the returned SkRegion instance.
static SkRegion* RawDraggableRegionsToSkRegion(
@@ -95,6 +98,7 @@ class ShellWindow : public content::NotificationObserver,
WindowType window_type() const { return window_type_; }
Profile* profile() const { return profile_; }
const gfx::Image& app_icon() const { return app_icon_; }
+ const GURL& app_icon_url() { return app_icon_url_; }
NativeAppWindow* GetBaseWindow();
gfx::NativeWindow GetNativeWindow();
@@ -221,6 +225,10 @@ class ShellWindow : public content::NotificationObserver,
// Used for loading app_icon_.
scoped_ptr<ImageLoadingTracker> app_icon_loader_;
+ // Icon URL to be used for setting the app icon. If not empty, app_icon_ will
+ // be fetched and set using this URL.
+ GURL app_icon_url_;
+
scoped_ptr<NativeAppWindow> native_app_window_;
DISALLOW_COPY_AND_ASSIGN(ShellWindow);
diff --git a/chrome/common/extensions/api/app_current_window_internal.idl b/chrome/common/extensions/api/app_current_window_internal.idl
index 782b882..469dafc 100644
--- a/chrome/common/extensions/api/app_current_window_internal.idl
+++ b/chrome/common/extensions/api/app_current_window_internal.idl
@@ -27,6 +27,7 @@
static void show();
static void hide();
static void setBounds(Bounds bounds);
+ static void setIcon(DOMString icon_url);
};
interface Events {
diff --git a/chrome/common/extensions/api/app_window.idl b/chrome/common/extensions/api/app_window.idl
index 7f88000..e719362 100644
--- a/chrome/common/extensions/api/app_window.idl
+++ b/chrome/common/extensions/api/app_window.idl
@@ -121,6 +121,11 @@ namespace app.window {
// Set the window's bounds.
static void setBounds(Bounds bounds);
+ // Set the app icon for the window (experimental).
+ // Currently this is only being implemented on Ash.
+ // TODO(stevenjb): Investigate implementing this on Windows and OSX.
+ [nodoc] static void setIcon(DOMString icon_url);
+
// The JavaScript 'window' object for the created child.
[instanceOf=global] object contentWindow;
};
diff --git a/chrome/test/data/extensions/platform_apps/windows_api_set_icon/background.js b/chrome/test/data/extensions/platform_apps/windows_api_set_icon/background.js
new file mode 100644
index 0000000..85029bd
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/windows_api_set_icon/background.js
@@ -0,0 +1,11 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+chrome.app.runtime.onLaunched.addListener(function() {
+ chrome.test.sendMessage("Launched");
+ chrome.app.window.create('test.html', {}, function(win) {
+ win.setIcon("icon.png");
+ chrome.test.sendMessage('IconSet');
+ });
+});
diff --git a/chrome/test/data/extensions/platform_apps/windows_api_set_icon/icon.png b/chrome/test/data/extensions/platform_apps/windows_api_set_icon/icon.png
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/windows_api_set_icon/icon.png
diff --git a/chrome/test/data/extensions/platform_apps/windows_api_set_icon/manifest.json b/chrome/test/data/extensions/platform_apps/windows_api_set_icon/manifest.json
new file mode 100644
index 0000000..e0db6ee
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/windows_api_set_icon/manifest.json
@@ -0,0 +1,9 @@
+{
+ "name": "app.windows setIcon",
+ "version": "1",
+ "app": {
+ "background": {
+ "scripts": ["background.js"]
+ }
+ }
+}
diff --git a/chrome/test/data/extensions/platform_apps/windows_api_set_icon/test.html b/chrome/test/data/extensions/platform_apps/windows_api_set_icon/test.html
new file mode 100644
index 0000000..c341a40
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/windows_api_set_icon/test.html
@@ -0,0 +1 @@
+<!-- empty -->