Hi Peng,

There is no requirement that AddJSHandler() be called with a unique
CefJSHandler
instance.  It just depends on what you're trying to do. If all of the
JavaScript objects are represented by the same class (MyJSHandler), and it's
important for the class implementation to know which JavaScript object it
represents ("myclass1", "myclass2" or "myclass3"), then each call to
AddJSHandler()
will need a different instance. One simple way to share state information
between the different MyJSHandler instances would be a pattern like the
following:

// BEGIN EXAMPLE

// Class representing data shared by all MyJSHandler instances
class MySharedData : public CefThreadSafeBase<CefBase>
{
public:
  // whatever data is shared
};

// The MyJSHandler implementation
class MyJSHandler : public CefThreadSafeBase<CefJSHandler>
{
public:
  // Pass the JavaScript object name and shared data object to the
constructor
  MyJSHandler(const std::wstring& name, CefRefPtr<MySharedData> sharedData)
  {
    m_Name = name;
    m_SharedData = sharedData;
  }

  // CefJSHandler method implementations here

protected:
  // Keep references to the name and shared data object for internal use
  std::wstring m_Name;
  CefRefPtr<MySharedData> m_SharedData;
}


// Register the JavaScript objects

  // Create the single shared data object
  CefRefPtr<MySharedData> SharedData(new MySharedData());

  // Create and add each MyJSHandler instance referencing the class name and
single shared data object
  browser->AddJSHandler(L"myclass1", new MyJSHandler(L"myclass1", SharedData
));
  browser->AddJSHandler(L"myclass2", new MyJSHandler(L"myclass2", SharedData
));
  browser->AddJSHandler(L"myclass3", new MyJSHandler(L"myclass3", SharedData
));

// END EXAMPLE

If, on the other hand, you want all of the JavaScript objects to use the
same CefJSHandler instance and you don't care which object is being acted
on, then you could call AddJSHandler() multiple times with the same
CefJSHandler instance.

// BEGIN EXAMPLE

// The MyJSHandler2 implementation
class MyJSHandler2 : public CefThreadSafeBase<CefJSHandler>
{
public:
  MyJSHandler2() {}

  // CefJSHandler method implementations here
}

// Register the JavaScript objects

  // Use the same MyJSHandler2 instance for all JS objects
  CefRefPtr<CefJSHandler> MyHandler(new MyJSHandler2());

  browser->AddJSHandler(L"myclass1", MyHandler);
  browser->AddJSHandler(L"myclass2", MyHandler);
  browser->AddJSHandler(L"myclass3", MyHandler);

// END EXAMPLE


Regards,
Marshall

On Fri, Dec 5, 2008 at 3:30 AM, chengyuan peng <[EMAIL PROTECTED]>wrote:

> Hi
>
> The chromium embedded framework (CEF) project is an excellent work! Thanks
> for the hard work.
>
> I have a maybe a stupid question as follows:
>
> In cefclient.cpp , if there are more than one class, say 3 classes, do I
> have to add the following code 3 times?
>
> // Register our JavaScript "myclass" object
>
> browser->AddJSHandler(L
> "myclass1", new AClientJSHandler());
>
>
>
> browser->AddJSHandler(L"myclass2", new BClientJSHandler());
>
>
>
> browser->AddJSHandler(L"myclass3", new CClientJSHandler());
>
>
>
> peng
>
>
>
> On Tue, Dec 2, 2008 at 6:04 PM, Marshall Greenblatt <
> [EMAIL PROTECTED]> wrote:
>
>> Hi All,
>>
>> The chromium embedded framework (CEF) project is now available for
>> download via svn:
>>
>> http://code.google.com/p/chromiumembedded/
>>
>> The CEF project is an extension of the Chromium project, and so to build
>> applications with CEF you must first download Chromium. The CEF files must
>> then be placed in the top-level Chromium directory, at the same level as the
>> "chrome" directory. For instance, if your Chromium installation directory is
>> C:\svn\Chromium then the CEF files should reside in C:\svn\Chromium\cef. The
>> CHROMIUM_BUILD_COMPATIBILITY file provides information about compatibility
>> between CEF and Chromium revisions.
>>
>> Regards,
>> Marshall >>
>>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Chromium-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/chromium-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to