Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5378)

Unified Diff: chrome/browser/extensions/extension_toolstrip_api.cc

Issue 160276: mole expand/collapse API (Closed)
Patch Set: fixed a couple of crashers Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/extension_toolstrip_api.h ('k') | chrome/browser/gtk/extension_shelf_gtk.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_toolstrip_api.cc
diff --git a/chrome/browser/extensions/extension_toolstrip_api.cc b/chrome/browser/extensions/extension_toolstrip_api.cc
new file mode 100644
index 0000000000000000000000000000000000000000..248eedb247500c9149ad499e3dbab2025d2840b7
--- /dev/null
+++ b/chrome/browser/extensions/extension_toolstrip_api.cc
@@ -0,0 +1,114 @@
+// Copyright (c) 2009 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 "chrome/browser/extensions/extension_toolstrip_api.h"
+
+#include "chrome/browser/browser.h"
+#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/extensions/extension_shelf_model.h"
+
+namespace extension_toolstrip_api_functions {
+const char kExpandFunction[] = "toolstrip.expand";
+const char kCollapseFunction[] = "toolstrip.collapse";
+}; // namespace extension_toolstrip_api_functions
+
+namespace {
+// Errors.
+const char kNotAToolstripError[] = "This page is not a toolstrip.";
+const char kAlreadyExpandedError[] = "This toolstrip is already expanded.";
+const char kAlreadyCollapsedError[] = "This toolstrip is already collapsed.";
+const char kInvalidURLError[] = "Invalid URL";
+const char kBadHeightError[] = "Bad height.";
+
+// TODO(erikkay) what are good values here?
+const int kMinHeight = 50;
+const int kMaxHeight = 1000;
+}; // namespace
+
+bool ToolstripFunction::RunImpl() {
+ ExtensionHost* host = dispatcher()->GetExtensionHost();
+ if (!host) {
+ error_ = kNotAToolstripError;
+ return false;
+ }
+ Browser* browser = dispatcher()->GetBrowser();
+ if (!browser) {
+ error_ = kNotAToolstripError;
+ return false;
+ }
+ model_ = browser->extension_shelf_model();
+ if (!model_) {
+ error_ = kNotAToolstripError;
+ return false;
+ }
+ toolstrip_ = model_->ToolstripForHost(host);
+ if (toolstrip_ == model_->end()) {
+ error_ = kNotAToolstripError;
+ return false;
+ }
+ return true;
+}
+
+bool ToolstripExpandFunction::RunImpl() {
+ if (!ToolstripFunction::RunImpl())
+ return false;
+ if (toolstrip_->height != 0) {
+ error_ = kAlreadyExpandedError;
+ return false;
+ }
+
+ EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
+ const ListValue* args = static_cast<const ListValue*>(args_);
+ EXTENSION_FUNCTION_VALIDATE(args->GetSize() <= 2);
+
+ int height;
+ EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &height));
+ EXTENSION_FUNCTION_VALIDATE(height >= 0);
+ if (height < kMinHeight || height > kMaxHeight) {
+ error_ = kBadHeightError;
+ return false;
+ }
+
+ GURL url;
+ if (args->GetSize() == 2) {
+ Value* url_val;
+ EXTENSION_FUNCTION_VALIDATE(args->Get(1, &url_val));
+ if (url_val->GetType() != Value::TYPE_NULL) {
+ std::string url_str;
+ EXTENSION_FUNCTION_VALIDATE(url_val->GetAsString(&url_str));
+ url = GURL(url_str);
+ if (!url.is_valid() && !url.is_empty()) {
+ error_ = kInvalidURLError;
+ return false;
+ }
+ }
+ }
+
+ model_->ExpandToolstrip(toolstrip_, url, height);
+ return true;
+}
+
+bool ToolstripCollapseFunction::RunImpl() {
+ if (!ToolstripFunction::RunImpl())
+ return false;
+
+ if (toolstrip_->height == 0) {
+ error_ = kAlreadyCollapsedError;
+ return false;
+ }
+
+ GURL url;
+ if (args_->GetType() != Value::TYPE_NULL) {
+ std::string url_str;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&url_str));
+ url = GURL(url_str);
+ if (!url.is_valid() && !url.is_empty()) {
+ error_ = kInvalidURLError;
+ return false;
+ }
+ }
+
+ model_->CollapseToolstrip(toolstrip_, url);
+ return true;
+}
« no previous file with comments | « chrome/browser/extensions/extension_toolstrip_api.h ('k') | chrome/browser/gtk/extension_shelf_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698