summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-01 20:25:23 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-01 20:25:23 +0000
commitcb2edf23d2553c6e13d070a33f9f2b9613d21ab1 (patch)
tree51c0b1125dba09b873d5f4bb6b63ae8c6ad35b17 /extensions
parent6ba8fcd3ec74b24afb75821236de78677081ad29 (diff)
downloadchromium_src-cb2edf23d2553c6e13d070a33f9f2b9613d21ab1.zip
chromium_src-cb2edf23d2553c6e13d070a33f9f2b9613d21ab1.tar.gz
chromium_src-cb2edf23d2553c6e13d070a33f9f2b9613d21ab1.tar.bz2
Move the ViewType enum to extensions\common.
BUG=162530 Review URL: https://codereview.chromium.org/13375017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191650 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions')
-rw-r--r--extensions/browser/view_type_utils.cc44
-rw-r--r--extensions/browser/view_type_utils.h24
-rw-r--r--extensions/common/view_type.cc19
-rw-r--r--extensions/common/view_type.h44
4 files changed, 131 insertions, 0 deletions
diff --git a/extensions/browser/view_type_utils.cc b/extensions/browser/view_type_utils.cc
new file mode 100644
index 0000000..a28381f
--- /dev/null
+++ b/extensions/browser/view_type_utils.cc
@@ -0,0 +1,44 @@
+// 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.
+
+#include "extensions/browser/view_type_utils.h"
+
+#include "base/lazy_instance.h"
+#include "content/public/browser/web_contents.h"
+
+using content::WebContents;
+
+namespace extensions {
+
+namespace {
+
+const char kViewTypeUserDataKey[] = "ViewTypeUserData";
+
+class ViewTypeUserData : public base::SupportsUserData::Data {
+ public:
+ explicit ViewTypeUserData(ViewType type) : type_(type) {}
+ virtual ~ViewTypeUserData() {}
+ ViewType type() { return type_; }
+
+ private:
+ ViewType type_;
+};
+
+} // namespace
+
+ViewType GetViewType(WebContents* tab) {
+ if (!tab)
+ return VIEW_TYPE_INVALID;
+
+ ViewTypeUserData* user_data = static_cast<ViewTypeUserData*>(
+ tab->GetUserData(&kViewTypeUserDataKey));
+
+ return user_data ? user_data->type() : VIEW_TYPE_INVALID;
+}
+
+void SetViewType(WebContents* tab, ViewType type) {
+ tab->SetUserData(&kViewTypeUserDataKey, new ViewTypeUserData(type));
+}
+
+} // namespace chrome
diff --git a/extensions/browser/view_type_utils.h b/extensions/browser/view_type_utils.h
new file mode 100644
index 0000000..4667be4
--- /dev/null
+++ b/extensions/browser/view_type_utils.h
@@ -0,0 +1,24 @@
+// 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.
+
+#ifndef EXTENSIONS_BROWSER_VIEW_TYPE_UTILS_H_
+#define EXTENSIONS_BROWSER_VIEW_TYPE_UTILS_H_
+
+#include "extensions/common/view_type.h"
+
+namespace content {
+class WebContents;
+}
+
+namespace extensions {
+
+// Get/Set the type of a WebContents.
+// GetViewType handles a NULL |tab| for convenience by returning
+// VIEW_TYPE_INVALID.
+ViewType GetViewType(content::WebContents* tab);
+void SetViewType(content::WebContents* tab, ViewType type);
+
+} // namespace chrome
+
+#endif // EXTENSIONS_BROWSER_VIEW_TYPE_UTILS_H_
diff --git a/extensions/common/view_type.cc b/extensions/common/view_type.cc
new file mode 100644
index 0000000..679532a
--- /dev/null
+++ b/extensions/common/view_type.cc
@@ -0,0 +1,19 @@
+// 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.
+
+#include "extensions/common/view_type.h"
+
+namespace extensions {
+
+const char kViewTypeTabContents[] = "TAB";
+const char kViewTypeBackgroundPage[] = "BACKGROUND";
+const char kViewTypePopup[] = "POPUP";
+const char kViewTypePanel[] = "PANEL";
+const char kViewTypeInfobar[] = "INFOBAR";
+const char kViewTypeNotification[] = "NOTIFICATION";
+const char kViewTypeExtensionDialog[] = "EXTENSION_DIALOG";
+const char kViewTypeAppShell[] = "SHELL";
+const char kViewTypeAll[] = "ALL";
+
+} // namespace extensions
diff --git a/extensions/common/view_type.h b/extensions/common/view_type.h
new file mode 100644
index 0000000..690ecab
--- /dev/null
+++ b/extensions/common/view_type.h
@@ -0,0 +1,44 @@
+// 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.
+
+#ifndef EXTENSIONS_COMMON_VIEW_TYPE_H_
+#define EXTENSIONS_COMMON_VIEW_TYPE_H_
+
+namespace extensions {
+
+// Icky RTTI used by a few systems to distinguish the host type of a given
+// WebContents.
+//
+// TODO(aa): Remove this and teach those systems to keep track of their own
+// data.
+enum ViewType {
+ VIEW_TYPE_INVALID,
+ VIEW_TYPE_APP_SHELL,
+ VIEW_TYPE_BACKGROUND_CONTENTS,
+ VIEW_TYPE_EXTENSION_BACKGROUND_PAGE,
+ VIEW_TYPE_EXTENSION_DIALOG,
+ VIEW_TYPE_EXTENSION_INFOBAR,
+ VIEW_TYPE_EXTENSION_POPUP,
+ // TODO(jam): remove this once http://crbug.com/137297 is fixed and HTML5
+ // notifications don't use WebContents.
+ VIEW_TYPE_NOTIFICATION,
+ VIEW_TYPE_PANEL,
+ VIEW_TYPE_TAB_CONTENTS,
+};
+
+// Constant strings corresponding to the Type enumeration values. Used
+// when converting JS arguments.
+extern const char kViewTypeAll[];
+extern const char kViewTypeAppShell[];
+extern const char kViewTypeBackgroundPage[];
+extern const char kViewTypeExtensionDialog[];
+extern const char kViewTypeInfobar[];
+extern const char kViewTypeNotification[];
+extern const char kViewTypePanel[];
+extern const char kViewTypePopup[];
+extern const char kViewTypeTabContents[];
+
+} // namespace extensions
+
+#endif // EXTENSIONS_COMMON_VIEW_TYPE_H_