Exemple #1
0
void StorageArea::dispatchSessionStorageEvent(
    const String& key,
    const String& oldValue,
    const String& newValue,
    SecurityOrigin* securityOrigin,
    const KURL& pageURL,
    const WebStorageNamespace& sessionNamespace,
    WebStorageArea* sourceAreaInstance) {
  Page* page = findPageWithSessionStorageNamespace(sessionNamespace);
  if (!page)
    return;

  for (Frame* frame = page->mainFrame(); frame;
       frame = frame->tree().traverseNext()) {
    // FIXME: We do not yet have a way to dispatch events to out-of-process
    // frames.
    if (!frame->isLocalFrame())
      continue;
    LocalFrame* localFrame = toLocalFrame(frame);
    LocalDOMWindow* localWindow = localFrame->domWindow();
    Storage* storage =
        DOMWindowStorage::from(*localWindow).optionalSessionStorage();
    if (storage &&
        localFrame->document()->getSecurityOrigin()->canAccess(
            securityOrigin) &&
        !isEventSource(storage, sourceAreaInstance))
      localFrame->domWindow()->enqueueWindowEvent(StorageEvent::create(
          EventTypeNames::storage, key, oldValue, newValue, pageURL, storage));
  }
  if (InspectorDOMStorageAgent* agent =
          StorageNamespaceController::from(page)->inspectorAgent())
    agent->didDispatchDOMStorageEvent(key, oldValue, newValue, SessionStorage,
                                      securityOrigin);
}
void StorageArea::dispatchLocalStorageEvent(const String& key, const String& oldValue, const String& newValue, SecurityOrigin* securityOrigin, const KURL& pageURL, WebStorageArea* sourceAreaInstance, bool originatedInProcess)
{
    // Iterate over all pages that have a StorageNamespaceController supplement.
    for (Page* page : Page::ordinaryPages()) {
        for (Frame* frame = page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
            // FIXME: We do not yet have a way to dispatch events to out-of-process frames.
            if (!frame->isLocalFrame())
                continue;
            LocalFrame* localFrame = toLocalFrame(frame);
            LocalDOMWindow* localWindow = localFrame->localDOMWindow();
            Storage* storage = DOMWindowStorage::from(*localWindow).optionalLocalStorage();
            if (storage && localFrame->document()->securityOrigin()->canAccess(securityOrigin) && !isEventSource(storage, sourceAreaInstance))
                localFrame->localDOMWindow()->enqueueWindowEvent(StorageEvent::create(EventTypeNames::storage, key, oldValue, newValue, pageURL, storage));
        }
        if (InspectorDOMStorageAgent* agent = StorageNamespaceController::from(page)->inspectorAgent())
            agent->didDispatchDOMStorageEvent(key, oldValue, newValue, LocalStorage, securityOrigin);
    }
}
void StorageAreaProxy::dispatchSessionStorageEvent(const String& key, const String& oldValue, const String& newValue,
                                                   SecurityOrigin* securityOrigin, const KURL& pageURL, const WebKit::WebStorageNamespace& sessionNamespace,
                                                   WebKit::WebStorageArea* sourceAreaInstance, bool originatedInProcess)
{
    Page* page = findPageWithSessionStorageNamespace(sessionNamespace);
    if (!page)
        return;

    for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
        Storage* storage = frame->document()->domWindow()->optionalSessionStorage();
        if (storage && frame->document()->securityOrigin()->equal(securityOrigin) && !isEventSource(storage, sourceAreaInstance))
            frame->document()->enqueueWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, pageURL, storage));
    }
    InspectorInstrumentation::didDispatchDOMStorageEvent(key, oldValue, newValue, SessionStorage, securityOrigin, page);
}
void StorageAreaProxy::dispatchLocalStorageEvent(const String& key, const String& oldValue, const String& newValue,
                                                 SecurityOrigin* securityOrigin, const KURL& pageURL, WebKit::WebStorageArea* sourceAreaInstance, bool originatedInProcess)
{
    // FIXME: This looks suspicious. Why doesn't this use allPages instead?
    const HashSet<Page*>& pages = PageGroup::sharedGroup()->pages();
    for (HashSet<Page*>::const_iterator it = pages.begin(); it != pages.end(); ++it) {
        for (Frame* frame = (*it)->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
            Storage* storage = frame->document()->domWindow()->optionalLocalStorage();
            if (storage && frame->document()->securityOrigin()->equal(securityOrigin) && !isEventSource(storage, sourceAreaInstance))
                frame->document()->enqueueWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, pageURL, storage));
        }
        InspectorInstrumentation::didDispatchDOMStorageEvent(key, oldValue, newValue, LocalStorage, securityOrigin, *it);
    }
}