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

Unified Diff: chrome/browser/ui/cocoa/applescript/apple_event_util.mm

Issue 11742028: Suspend Apple Events during their processing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 7 years, 12 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
Index: chrome/browser/ui/cocoa/applescript/apple_event_util.mm
diff --git a/chrome/browser/ui/cocoa/applescript/apple_event_util.mm b/chrome/browser/ui/cocoa/applescript/apple_event_util.mm
new file mode 100644
index 0000000000000000000000000000000000000000..2805f305fb90535a916cc5e7c1873108fed78a10
--- /dev/null
+++ b/chrome/browser/ui/cocoa/applescript/apple_event_util.mm
@@ -0,0 +1,102 @@
+// Copyright (c) 2013 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.
+
+#import "chrome/browser/ui/cocoa/applescript/apple_event_util.h"
+
+#import <Carbon/Carbon.h>
+
+#include "base/logging.h"
+#include "base/sys_string_conversions.h"
+#include "base/values.h"
+
+namespace chrome {
+namespace mac {
+
+NSAppleEventDescriptor* ValueToAppleEventDescriptor(const base::Value* value) {
+ NSAppleEventDescriptor* descriptor = nil;
+
+ switch (value->GetType()) {
+ case base::Value::TYPE_NULL:
+ descriptor = [NSAppleEventDescriptor
+ descriptorWithTypeCode:cMissingValue];
+ break;
+
+ case base::Value::TYPE_BOOLEAN: {
+ bool bool_value;
+ value->GetAsBoolean(&bool_value);
+ descriptor = [NSAppleEventDescriptor descriptorWithBoolean:bool_value];
+ break;
+ }
+
+ case base::Value::TYPE_INTEGER: {
+ int int_value;
+ value->GetAsInteger(&int_value);
+ descriptor = [NSAppleEventDescriptor descriptorWithInt32:int_value];
+ break;
+ }
+
+ case base::Value::TYPE_DOUBLE: {
+ double double_value;
+ value->GetAsDouble(&double_value);
+ descriptor = [NSAppleEventDescriptor
+ descriptorWithDescriptorType:typeIEEE64BitFloatingPoint
+ bytes:&double_value
+ length:sizeof(double_value)];
+ break;
+ }
+
+ case base::Value::TYPE_STRING: {
+ std::string string_value;
+ value->GetAsString(&string_value);
+ descriptor = [NSAppleEventDescriptor descriptorWithString:
+ base::SysUTF8ToNSString(string_value)];
+ break;
+ }
+
+ case base::Value::TYPE_BINARY:
+ NOTREACHED();
+ break;
+
+ case base::Value::TYPE_DICTIONARY: {
+ const base::DictionaryValue* dictionary_value;
+ value->GetAsDictionary(&dictionary_value);
+ descriptor = [NSAppleEventDescriptor recordDescriptor];
+ NSAppleEventDescriptor* userRecord = [NSAppleEventDescriptor
+ listDescriptor];
+ for (DictionaryValue::key_iterator iter(dictionary_value->begin_keys());
+ iter != dictionary_value->end_keys(); ++iter) {
+ const base::Value* item;
+ if (dictionary_value->Get(*iter, &item)) {
+ [userRecord insertDescriptor:[NSAppleEventDescriptor
+ descriptorWithString:base::SysUTF8ToNSString(*iter)]
+ atIndex:0];
+ [userRecord insertDescriptor:ValueToAppleEventDescriptor(item)
+ atIndex:0];
+ }
+ }
+ // Description of what keyASUserRecordFields does.
+ // http://lists.apple.com/archives/cocoa-dev/2009/Jul/msg01216.html
+ [descriptor setDescriptor:userRecord forKeyword:keyASUserRecordFields];
+ break;
+ }
+
+ case base::Value::TYPE_LIST: {
+ const base::ListValue* list_value;
+ value->GetAsList(&list_value);
+ descriptor = [NSAppleEventDescriptor listDescriptor];
+ for (size_t i = 0; i < list_value->GetSize(); ++i) {
+ const base::Value* item;
+ list_value->Get(i, &item);
+ [descriptor insertDescriptor:ValueToAppleEventDescriptor(item)
+ atIndex:0];
+ }
+ break;
+ }
+ }
+
+ return descriptor;
+}
+
+} // namespace mac
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698