| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/extension_toolstrip_api.h" | 5 #include "chrome/browser/extensions/extension_toolstrip_api.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 bool ToolstripExpandFunction::RunImpl() { | 61 bool ToolstripExpandFunction::RunImpl() { |
| 62 if (!ToolstripFunction::RunImpl()) | 62 if (!ToolstripFunction::RunImpl()) |
| 63 return false; | 63 return false; |
| 64 if (toolstrip_->height != 0) { | 64 if (toolstrip_->height != 0) { |
| 65 error_ = kAlreadyExpandedError; | 65 error_ = kAlreadyExpandedError; |
| 66 return false; | 66 return false; |
| 67 } | 67 } |
| 68 | 68 |
| 69 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); | 69 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); |
| 70 const DictionaryValue* args = static_cast<const DictionaryValue*>(args_); | 70 const DictionaryValue* args = args_as_dictionary(); |
| 71 | 71 |
| 72 int height; | 72 int height; |
| 73 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey, | 73 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey, |
| 74 &height)); | 74 &height)); |
| 75 EXTENSION_FUNCTION_VALIDATE(height >= 0); | 75 EXTENSION_FUNCTION_VALIDATE(height >= 0); |
| 76 if (height < kMinHeight || height > kMaxHeight) { | 76 if (height < kMinHeight || height > kMaxHeight) { |
| 77 error_ = kBadHeightError; | 77 error_ = kBadHeightError; |
| 78 return false; | 78 return false; |
| 79 } | 79 } |
| 80 | 80 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 99 return false; | 99 return false; |
| 100 | 100 |
| 101 if (toolstrip_->height == 0) { | 101 if (toolstrip_->height == 0) { |
| 102 error_ = kAlreadyCollapsedError; | 102 error_ = kAlreadyCollapsedError; |
| 103 return false; | 103 return false; |
| 104 } | 104 } |
| 105 | 105 |
| 106 GURL url; | 106 GURL url; |
| 107 if (args_->GetType() != Value::TYPE_NULL) { | 107 if (args_->GetType() != Value::TYPE_NULL) { |
| 108 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); | 108 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); |
| 109 const DictionaryValue* args = static_cast<const DictionaryValue*>(args_); | 109 const DictionaryValue* args = args_as_dictionary(); |
| 110 | 110 |
| 111 if (args->HasKey(keys::kUrlKey)) { | 111 if (args->HasKey(keys::kUrlKey)) { |
| 112 std::string url_string; | 112 std::string url_string; |
| 113 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kUrlKey, | 113 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kUrlKey, |
| 114 &url_string)); | 114 &url_string)); |
| 115 url = dispatcher()->url().Resolve(url_string); | 115 url = dispatcher()->url().Resolve(url_string); |
| 116 if (!url.is_valid()) { | 116 if (!url.is_valid()) { |
| 117 error_ = kInvalidURLError; | 117 error_ = kInvalidURLError; |
| 118 return false; | 118 return false; |
| 119 } | 119 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 void ToolstripEventRouter::OnToolstripCollapsed(Profile* profile, | 156 void ToolstripEventRouter::OnToolstripCollapsed(Profile* profile, |
| 157 int routing_id, | 157 int routing_id, |
| 158 const GURL &url) { | 158 const GURL &url) { |
| 159 ListValue args; | 159 ListValue args; |
| 160 DictionaryValue* obj = new DictionaryValue(); | 160 DictionaryValue* obj = new DictionaryValue(); |
| 161 if (!url.is_empty()) | 161 if (!url.is_empty()) |
| 162 obj->SetString(keys::kUrlKey, url.spec()); | 162 obj->SetString(keys::kUrlKey, url.spec()); |
| 163 args.Append(obj); | 163 args.Append(obj); |
| 164 DispatchEvent(profile, routing_id, events::kOnToolstripCollapsed, args); | 164 DispatchEvent(profile, routing_id, events::kOnToolstripCollapsed, args); |
| 165 } | 165 } |
| OLD | NEW |